Saturday 4 June 2011

School Homework. thanks in advance?

Answer the following questions as briefly (but completely) as possible. Unless otherwise stated, assume a POSIX shell (such as bash) is used.





1.Using wild cards, frame a pattern where the first character is alphabetic and the last is not numeric.





2.How do you remove a file beginning with a hyphen in the $HOME/foo directory?





3.What happens when you use cat foo %26gt; foo? What about sort -f foo %26lt; foo





4.What is a filter command? Where does a filter get its input from?





5.What are two consequences of using double quotes?





6.What are two environment variables are set by reading /etc/passwd when you login? (Actually there are 4.)





7.How would you add the current directory (no matter what it is) to you existing PATH? Why would that be a bad idea?





8.If you run PS1=%26#039;\!$%26#039;, what sort of prompt will you get using the Korn shell or bash?





9.Write a Korn or bash shell alias to list only the hidden files of the current directory. (Extra credit if your alias doesn%26#039;t list . or .. entries.)





10.You have just used the command tar -cvf /dev/fd0 *.sh. How can you repeat the command to use *.pl files instead of *.sh files, in the bash shell, without retyping the entire command?





11.If your .profile contains statements like PATH=$PATH:$HOME/bin and PS1=%26#039;$PWD$ %26#039; and you make any changes to the file, how should you activate the changes?|||1.Using wild cards, frame a pattern where the first character is alphabetic and the last is not numeric.


^[a-zA-Z]*[a-zA-Z]$





2.How do you remove a file beginning with a hyphen in the $HOME/foo directory?


rm $HOME/foo/\-*





3.What happens when you use cat foo %26gt; foo? What about sort -f foo %26lt; foo


cat foo %26gt; foo: foo will be a file size 0. Empty file.


sort -f foo %26lt; foo: foo will be a file size 0. Empty file.





4.What is a filter command? Where does a filter get its input from?


Filter is a concept of excluding/including certain info from the original output. Input is from an output of another command.





5.What are two consequences of using double quotes?








6.What are two environment variables are set by reading /etc/passwd when you login? (Actually there are 4.)


USERNAME (or is it USERID)


HOME


GROUP








7.How would you add the current directory (no matter what it is) to you existing PATH? Why would that be a bad idea?


export PATH=$PATH:`pwd`


Bad idea: Every time you do a cd, your path will keep expanding.





8.If you run PS1=%26#039;\!$%26#039;, what sort of prompt will you get using the Korn shell or bash?


My guess is last command you ran.





9.Write a Korn or bash shell alias to list only the hidden files of the current directory. (Extra credit if your alias doesn%26#039;t list . or .. entries.)


alias ls=`/bin/ls | grep ^\. | grep -v \. | grep -v \.\.`





10.You have just used the command tar -cvf /dev/fd0 *.sh. How can you repeat the command to use *.pl files instead of *.sh files, in the bash shell, without retyping the entire command?


use up arrow key, two backspaces and type sh.


if you set the vi editor, you can use %26quot;k$llRpl%26quot; and enter





11.If your .profile contains statements like PATH=$PATH:$HOME/bin and PS1=%26#039;$PWD$ %26#039; and you make any changes to the file, how should you activate the changes?


%26quot;. $HOME/.profile%26quot; (no quotes) or if .profile is set to have %26#039;x%26#039; flag for owner, just $HOME/.profile will do











All these questions can be easily solved by trying it yourself on the unix shell. All of the answers are from memory. do not have a handy machine with *nix loaded to validate the answers. Good luck!|||If other people do your homework for you then you are not learning anything|||7. PATH=$PATH%26quot;;%26quot;`pwd`; #iirc


8. \!$


5. i) you have to escape all special characters








(i%26#039;m so gonna fail systems programming)