28.bash3.ans.even.RH4

Practical Guide to Fedora and Red Hat Enterprise Linux, A (4th Edition)

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Answers to Even-numbered Exercises 1. pt works. 2. The special parameter " $@ " is referenced twice in the out script (page 909). Explain what would be different if the parameter " $ * " were used in its place. If you replace " $@ " with " $ * " in the out script, cat or less would be given a single argument: a list of all files you specified on the command line enclosed within single quotation marks. This list works when you specify a single filename. When you specify more than one file, the shell reports No such file or directory because there is not a file named the string you speci- fied on the command line (the SPACE s are not special characters when they are enclosed within single quotation marks). 3. Wrthe list. 4. Write a function that takes a single filename as an argument and adds exe- cute permission to the file for the user. $ function perms () { > chmod u+x $1 > } a. When might such a function be useful? When you are writing many shell scripts, it can be tedious to give many chmod commands. This function speeds up the process. b. Revise the script so that it takes one or more filenames as arguments and adds execute permission for the user for each file argument. $ function perms { > chmod u+x $* > } c. What can you do to make the function available every time you log in? 28
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Put the function in ~/.bash_profile and/or ~/.bashrc to make it available each time you log in (using bash ). d. Suppose that, in addition to having the function available on subsequent login sessions, you want to make the function available now in your current shell. How would you do so? Use source to execute the file you put the function in, for example, $ source ~/.bash_profile 5. When k of. 6. Write a shell script that displays the names of all directory files, but no other types of files, in the working directory. There are many ways to solve this problem. The listdirs script uses file to identify directory files and grep to pull them out of the list. Then sed removes everything from file ’s output, starting with the colon. $ cat listdirs
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

28.bash3.ans.even.RH4 - 28 Answers to Even-numbered...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online