Bash script in linux 7
A Bash shell script can be created by opening a new empty file in a text editor. while any text editor con be user, advanced editor, such as vim or emacs, understand Bash shell syntax and con provide color-coded highlighting. This highlighting con be a tremendous help for spotting syntactical errors, such as unpaired quotes, unclosed brackets, and other common blunders.
The command interpreter
The first line of a bash shell script begins with '#!', also commonly referred to as a sharp-band or the abbreviated version, sha-bang. This two-byte notation is technically referred to as the magic pattern. it indicates that the file is an executable shell script. The path name that follows is the command interpreter, the program that should be used to execute the script. Since bash shell scripts are to be interpreted by the bash shell, they begin with the following first line.
#vim /root/script.sh
Entry :-
#!/bin/bash
if [ “$1” == “bar” ]
then
echo “foo”
elif [ “$1” == “foo” ]
then
echo “bar”
else
echo “/root/script.sh foo|bar”
fi
(save file)
You type:-
#sh /root/script.sh
Result :- /root/script.sh foo|bar
And
# sh /root/script.sh foo
Result :- bar
# sh /root/script.sh bar
Result :- foo
You also watch my video :-
The command interpreter
The first line of a bash shell script begins with '#!', also commonly referred to as a sharp-band or the abbreviated version, sha-bang. This two-byte notation is technically referred to as the magic pattern. it indicates that the file is an executable shell script. The path name that follows is the command interpreter, the program that should be used to execute the script. Since bash shell scripts are to be interpreted by the bash shell, they begin with the following first line.
#vim /root/script.sh
Entry :-
#!/bin/bash
if [ “$1” == “bar” ]
then
echo “foo”
elif [ “$1” == “foo” ]
then
echo “bar”
else
echo “/root/script.sh foo|bar”
fi
(save file)
You type:-
#sh /root/script.sh
Result :- /root/script.sh foo|bar
And
# sh /root/script.sh foo
Result :- bar
# sh /root/script.sh bar
Result :- foo
You also watch my video :-
Comments
Post a Comment