2009年7月25日星期六

Advanced Bash-Scripting Guide 1 - 6

for file in /{,usr/}bin/*calc 
# ^ Find all executable files ending in "calc" 
#+ in /bin and /usr/bin directories. 
do 
if [ -x "$file" ] 
then 
echo $file 
fi 
done
#!/bin/sed -f 
#!/usr/awk -f
tail -n $lines messages > mesg.temp # Save last section of message log file. 
mv mesg.temp messages # Becomes new log directory.
   echo {0..3} # 0 1 2 3

exit status variable. The $? variable holds the exit status of a command, a function, or of the script itself.

hello="A B C D" 
echo $hello # A B C D 
echo "$hello" # A B C D 
# As you see, echo $hello and echo "$hello" give different results. 
# Why? 
# ======================================= 
# Quoting a variable preserves whitespace. 
# =======================================

~+ current working directory. This corresponds to the $PWD internal variable.
~- previous working directory. This corresponds to the $OLDPWD internal variable.

let "z = 5 % 3" 
echo $z # 2

>| force redirection (even if the noclobber option is set). This will forcibly overwrite an existing file.

command >&2 redirects stdout of command to stderr.

没有评论:

发表评论