Chapter 6 Challenges

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to: navigation, search
← Executes commands and send output to the file descriptor (fd)HomeChapter 7: Pipes and Filters →
  • Decide whether the following sentence is true or false:
  1. To create empty file use >filename.
  2. If no files given cat command reads from standard input.
  3. The standard input defaults to user keyboard.
  4. 0<filename takes standard input from file.
  5. 2>filename puts standard output to file.
  6. ./script.sh 2>&1 puts standard error to current destination of standard output.
  7. >output.txt if output.txt doesn't exist it is created and if it exist it is overwritten.
  8. The order in which you place redirection is significant.
  9. The following command will generate an error message - </etc/passwd grep vivek
  10. The following two commands will produced the same results:
sort < input.txt > output.txt
sort > output.txt < input.txt 
  • Write a shell command that associates the file descriptor 2 to a file called log.txt and send fd # 2 to a log.txt instead of the screen. Then associates fd # 1 with the file associated with the fd # 2.
  • Write a shell script to open /etc/passwd file using fd (input) and copy the same to /tmp/passwd.output file using file descriptor (output).
← Executes commands and send output to the file descriptor (fd)HomeChapter 7: Pipes and Filters →