I wrote as sh file.When I execute it it doesn't work correctly.But by using same commands to command prompt independently it works.What may be the problem?I am a newbie in shell scripting.So any help will be appreciated.Here is my sh file including:
mkdir prelab5
cd prelab5
wget http://cse.yeditepe.edu.tr/~oturkes/spring2011/cse232/week7/rms.txt &
grep "free" rms.txt | tail -n 10 > free.txt
cd ..
find /home/misafir -perm -755
chmod 744 file.txt
grep "free" rms.txt | wc
tr 'a-z' 'A-Z'<free.txt
Background process means that it is worked in the background and let us to use开发者_StackOverflow中文版 terminal simultaneously.Also,while we let working the process in the background,we can see a unique process id (pid) of this background process on the screen.Therefore,by using this unique pid we can execute some any commands on this bckground working process.
remove the ampersand at the end of wget command.
shell executes the commands faster than you type them; when you grep the "free" wget probably isnt finished yet
wget hasn't finished (and probably hasn't even started) by the time grep runs. Remove the ampersand at the end of the wget line, and add it to the script invocation instead.
The first problem is the & on the wget line. It starts the wget in the background, and then immediately greps rms.txt - but that file probably hasn't finished being downloaded yet. Remove the & and it should be fine.
The second problem is that after you cd ..
, rms.txt and free.txt are no longer in the current working directory, so the last two lines refer to files that appear not to exist.
Lastly, it's very unclear what you're trying to accomplish with the find - as you've written it, it'll just print a bunch of stuff to the terminal. Similarly, it's unclear what file.txt is supposed to be - it's not referred to anywhere else.
In general, it's helpful if you give an indication of what your goal is in addition to the problem code.
There are different problems in your script. At the point that I am not sure that you know what each line is doing. so
mkdir prelab5 # create a dire prelab5
cd prelab5 # change dir to prelab5
wget http://cse.yeditepe.edu.tr/.../rms.txt & #dl rms.txt
grep "free" rms.txt | tail -n 10 > free.txt
This last script line puts 10 lines of rms.txt containing free in free.txt. At this point rms.txt probably does not exist yet. You better remove the & at the end of the previous line in order to execute each line sequencially.
cd .. # go back to the parent directory
find /home/misafir -perm -755
This line search for files somewhere else but the result is not used.
chmod 744 file.txt # Modify a file we didn't hear about before
grep "free" rms.txt | wc # Should fail since rms.txt is not in this directory
tr 'a-z' 'A-Z'<free.txt # Doesn't work this way
精彩评论