Sunday, 15 August 2010

bash - writing a loop in Unix that reads user input yes or no -


I am trying to write a program that will display the running processes and ask the user if they are each process My code is here to kill

  #! / Bin / bash ps pid tte time cmd 1681 points / 1 00:00:00 tcs 1690 points / 00 00:00 bash 1708 points / 1 00:00:00 script 1710 points / 00 00:00 ps Ps | While reading the line; Id = $ (echo $ line | cut-d '' -f1) name = $ (echo $ line | cut-d '' -f 4) echo 'process id:' $ id 'name:' $ name echo - N 'Do you want to kill this process? Yes / No: Read the word & lt; / Dev / tty if [$ word == 'yes']; So kill $ id  

I have two problems ... One is that when I do not write I get an error line 10 [no: command not found . Second, it is that when I specify the variable for the ID and name, it automatically reads the first row that I

  process id: name: cmd  

If your if is incorrect:

  If [" $ Word "=" yes "] ^^^^^^^^ - Note the space around the quotes around var.  

Additionally, [ does not use == for parity testing. This is just = is.


No comments:

Post a Comment