Changes

Jump to navigation Jump to search
108 bytes added ,  22:50, 29 March 2016
m
Text replacement - "</source>" to "</syntaxhighlight>"
Line 6: Line 6:  
<syntaxhighlight lang="bash" >echo "$PATH"
 
<syntaxhighlight lang="bash" >echo "$PATH"
 
echo "$PS1"
 
echo "$PS1"
echo /etc/*.conf</source>
+
echo /etc/*.conf</syntaxhighlight>
 
However, sometime you do not wish to use variables or [[wildcards]]. For example, do not print value of $PATH, but just print $PATH on screen as a word. You can enable or disable the meaning of a special character by enclosing them in single quotes. This is also useful to suppress warnings and error messages while writing the shell scripts.  
 
However, sometime you do not wish to use variables or [[wildcards]]. For example, do not print value of $PATH, but just print $PATH on screen as a word. You can enable or disable the meaning of a special character by enclosing them in single quotes. This is also useful to suppress warnings and error messages while writing the shell scripts.  
<syntaxhighlight lang="bash" >echo "Path is $PATH"  ## $PATH will be expanded</source>
+
<syntaxhighlight lang="bash" >echo "Path is $PATH"  ## $PATH will be expanded</syntaxhighlight>
 
OR
 
OR
<syntaxhighlight lang="bash" >echo 'I want to print $PATH' ## PATH will not be expanded</source>
+
<syntaxhighlight lang="bash" >echo 'I want to print $PATH' ## PATH will not be expanded</syntaxhighlight>
 
==Quoting==
 
==Quoting==
 
There are three types of quotes:
 
There are three types of quotes:
Line 39: Line 39:  
The backslash ( \ ) alters the special meaning of the ' and " i.e. it will escape or cancel the special meaning of the next character. The following will display filename in double quote:
 
The backslash ( \ ) alters the special meaning of the ' and " i.e. it will escape or cancel the special meaning of the next character. The following will display filename in double quote:
 
<syntaxhighlight lang="bash" >FILE="/etc/resolv.conf"
 
<syntaxhighlight lang="bash" >FILE="/etc/resolv.conf"
echo "File is \"$FILE\" "</source>
+
echo "File is \"$FILE\" "</syntaxhighlight>
 
Sample Outputs:
 
Sample Outputs:
 
<pre>File is "/etc/resolv.conf"</pre>
 
<pre>File is "/etc/resolv.conf"</pre>
 
The following will remove the special meaning of the dollar ( $ ) sign:
 
The following will remove the special meaning of the dollar ( $ ) sign:
 
<syntaxhighlight lang="bash" >FILE="/etc/resolv.conf"
 
<syntaxhighlight lang="bash" >FILE="/etc/resolv.conf"
echo "File is \$FILE "</source>
+
echo "File is \$FILE "</syntaxhighlight>
 
Sample Outputs:
 
Sample Outputs:
 
<pre>File is $FILE </pre>
 
<pre>File is $FILE </pre>
Line 72: Line 72:  
echo -e "Sr.no\t DVD (price) "
 
echo -e "Sr.no\t DVD (price) "
 
echo -e "1\t Spirited Away (INR.200)"
 
echo -e "1\t Spirited Away (INR.200)"
echo -e "2\t Dragon Ball Z (INR.300)"</source>
+
echo -e "2\t Dragon Ball Z (INR.300)"</syntaxhighlight>
 
The special parameters * and @ have special meaning when in double quotes, but you can disable them with the backslash:
 
The special parameters * and @ have special meaning when in double quotes, but you can disable them with the backslash:
 
<syntaxhighlight lang="bash" >echo "*"
 
<syntaxhighlight lang="bash" >echo "*"
 
echo "\*"
 
echo "\*"
echo "\@"</source>
+
echo "\@"</syntaxhighlight>
 
====Continue command on next line====
 
====Continue command on next line====
 
You can use the backslash (\) as last character on line to continue command on next line:
 
You can use the backslash (\) as last character on line to continue command on next line:
 
<syntaxhighlight lang="bash" >echo "A monkey-tailed boy named Goku is found by an old martial \
 
<syntaxhighlight lang="bash" >echo "A monkey-tailed boy named Goku is found by an old martial \
 
>arts expert who raises him as his grandson. One day Goku meets a \
 
>arts expert who raises him as his grandson. One day Goku meets a \
>girl named Bulma and together they go on a quest to retrieve the seven Dragon Balls"</source>
+
>girl named Bulma and together they go on a quest to retrieve the seven Dragon Balls"</syntaxhighlight>
 
You can also use the backslash while writing program or [[Writing_your_first_shell_function|function]]:
 
You can also use the backslash while writing program or [[Writing_your_first_shell_function|function]]:
 
<syntaxhighlight lang="bash" ># Purpose: clean /tmp/$domain ?
 
<syntaxhighlight lang="bash" ># Purpose: clean /tmp/$domain ?
Line 91: Line 91:  
           -a -e /usr/local/etc/nixcraft/lighttpd/disk_cache.init ] && return 0
 
           -a -e /usr/local/etc/nixcraft/lighttpd/disk_cache.init ] && return 0
 
         return 1
 
         return 1
}</source>
+
}</syntaxhighlight>
    
====Protecting command line arguments====
 
====Protecting command line arguments====
 
Type the following command to find out all c program file (*.c):
 
Type the following command to find out all c program file (*.c):
<syntaxhighlight lang="bash" >find $HOME -name *.c</source>
+
<syntaxhighlight lang="bash" >find $HOME -name *.c</syntaxhighlight>
 
In the above example, the *.c is expanded by the bash shell. It will try to match all filename ending with .c in the /home directory (current user's home directory) such as main.c, lib1.c, lib2.c, ssh.c, auth.c etc. You can escape the wild card using the backslash as the escape character:
 
In the above example, the *.c is expanded by the bash shell. It will try to match all filename ending with .c in the /home directory (current user's home directory) such as main.c, lib1.c, lib2.c, ssh.c, auth.c etc. You can escape the wild card using the backslash as the escape character:
 
<syntaxhighlight lang="bash" >find $HOME -name \*.c
 
<syntaxhighlight lang="bash" >find $HOME -name \*.c
 
find $HOME -name \*main.c
 
find $HOME -name \*main.c
find /nas01/apps/admin -iname \*py </source>
+
find /nas01/apps/admin -iname \*py </syntaxhighlight>
 
You can also use the double quote  
 
You can also use the double quote  
<syntaxhighlight lang="bash" >find $HOME -name "*.c"</source>
+
<syntaxhighlight lang="bash" >find $HOME -name "*.c"</syntaxhighlight>
    
[[Category:Variables and Quoting]]
 
[[Category:Variables and Quoting]]

Navigation menu