Locations of visitors to this page

Wednesday, June 24, 2009

shell script quiz SHELL脚本小测验

shell script quiz
SHELL脚本小测验


Questions:
1. What dose BASH stand for? Who is its original developer?

2. How to set your prompt so that it displays your login name, hostname and your location in the file system hierarchy?

3. Someone wrote the following code snippet.
while read LINE
do
  echo $LINE
done < `tail -f /var/log/messages`

He wished to write a script tracking changes to the system log file, /var/log/messages. Unfortunately, the above code block hangs and does nothing useful. Why? Fix this so it does work. (Hint: rather than redirecting the stdin of the loop, try a pipe.)

4. How to convert hexadecimal to decimal number in BASH scripting and vice versa?

5. Analyze the following script and explain what it does.
for f in *.foo; do
  mv $f ${f%foo}bar
 done











Answers:
1. BASH is an acronym which stands for Bourne-again shell. It was originally written by Brian Fox in 1987.

2. add this line to ~/.bashrc:
export PS1="\u@\h \w> "

3.
"<" is the operator of input redirection, it can accept input from a file.
example: grep search-word <filename

tail -f /var/log/messages |while read LINE
do
  echo $LINE
done

4.
hex2dec: echo $[0xfe]
dec2hex: printf "%x\n" 254

5. Rename filename "*.foo" to "*.bar" in current directory.



-fin-

No comments:

Website Analytics

Followers