RHEL 7 RHCE EXAM OBJECTIVE SOLUTION - BASHSCRIPTING WITH ARGUMENTS

BASH SCRIPTING WITH ARGUMENTS

Create a script to take the command line argument input of foo or bar. The output should echo foo or bar depending on which is used as the script argument. If neither foo or bar are part of the command line argument , then output "foo | bar".

[root@rhel7-exam-objectives ~]# vi foobar.sh
#!/bin/bash

if [[ $1 == "foo" ]]; then
echo "foo";
elif [[ $1 == "bar" ]]; then
echo "bar";
else
echo "foo | bar";
fi

chmod +x foobar.sh