Elementary Script Trouble
When testing my script for a question, I find that when I execute the
expanded commands, I get no error message, but when I source the file with the command, I get 'No such file or directory'. Here is what I mean: Code:
mwesolow@linux016:~/cs246/1$ ./q1c Here is my actual 'script': Code:
#!/bin/bash Thanks |
Type this exactly at a shell prompt and look at the results
Code:
"/bin/echo hi there" Once you realize why that causes an error, then review your script for something similar. I'm avoiding a direct answer for a reason. This is obviously a programming assignment. And LQ policy is not to give answers to those kinds of questions. However, nudging and pointing-in-the-right-direction tends to be ok. So, the above is all I can say without answering it directly. |
Hi -
I'm a bit confused about a number of things you're trying to do. But this snippet might help: Code:
#!/bin/bash I noticed Dark Helmet and I posted at the same time. He's correct - I encourage you to follow his advice and figure out why. But that's not the only problem with your script. Please post back with what you find, and your final (working) version! |
Thank you for your kind replies!
Yes, this is a programming assignment, so thank you for considering that. Here is the final working script: Code:
#!/bin/bash |
I'm glad we could help.
You might continue refining this script in the course, or the instructor might throw different types of input to test how robust your script is. So, I'd also like to give you a heads-up on a potential hiccup. This might be one of the things 14moose was getting at also. It might be a good idea for you to read up on the special variable IFS (man bash). Your use of double quotes around filenames with the cp command tells me that you're concerned the filenames might, for instance, have spaces in them. If that is the case, your for loop will not behave as you expect. As an example, try the following: Code:
$ mkdir testing |
I see the problem now. I suppose I could set IFS to some non-printable character to reduce all likelihood of a problem, and then set it back to <space><tab><newline> at the end. But if there is a way to get around this without changing environment variables, that would be preferable.
My bash scripts will be tested automatically, so I don't know if we will even have rights to change IFS (I will ask, but this seems a bit much for question 1c on the first assignment). |
Try the same example provided by Dark Helmet but try changing the for loop to use globbing:
Code:
for x in *; do echo "$x"; done |
IFS is just a shell var (albeit automatically setup for you). Any shell prog can change its own copy, but of course, you cannot export it back up the process tree
Typically you'd use it something like this http://www.tldp.org/LDP/abs/html/int...bles.html#IFSH |
All times are GMT -5. The time now is 09:20 PM. |