标签:
A shell script is a text file that typically begins with a shebang, as follows:
#!/bin/bash
/bin/bash is
the interpreter command path for Bash.
$ sh /home/path/script.sh # Using full path of script.sh.
chmod a+x script.sh
#character is used to denote the beginning of unprocessed comments.
For every
process, environment variables in its runtime can be viewed by:
cat /proc/$PID/environ
cat /proc/12501/environ
cat /proc/2849/environ | tr ‘\0‘ ‘\n‘
Then you can split the environment string to property=value format.
Judge the current user is super user or not:
if [ $UID -ne 0 ]; then
echo Non root user. Please run as root.
else
echo "Root user"
Fi
File descriptors are integers that are associated with file input and output. They keep track
of opened files. The best-known file descriptors are stdin, stdout, and stderr.
0 – stdin(standard input)
1 – stdout(standard output)
2 – stderr(standard error)
#!/bin/bash #Description: Illustration of IFS line="root:x:0:0:root:/root:/bin/bash" oldIFS=$IFS; IFS=":" count=0 for item in $line; do [ $count -eq 0 ] && user=$item; [ $count -eq 6 ] && shell=$item; let count++ done; IFS=$oldIFS echo $user\‘s shell is $shell;
标签:
原文地址:http://www.cnblogs.com/huaxiaoyao/p/4291392.html