Help With Homework Assignment
I'm having some issue with a homework assignment on shell scripting. The instructor gave me this pseudo code:
Code:
BEGIN Code:
#! /bin/sh |
I'm assuming the purpose of this script is to find whether or not the file issued as an argument actually exists or not..?
You're close, I think. As a general rule, it's a good idea to "protect" your variables. So instead of writing things like Code:
$P/$file Code:
${P}/${file} For instance, before entering an 'if' statement, precede it with a simple Code:
echo "DEBUG: an if statement to test if file is exec or not" |
Within the test command, the '=' and '==' are equivalent for bash. In fact, '=' is more compatible with sh.
You should certainly analyze the errors generated by the script. Also try using the 'bash -x' option to enter debug mode. Also see: http://www.cyberciti.biz/tips/debugg...ll-script.html |
As not mentioned earlier, please place code / data in [code][/code] tags so it is more readable and maintains your formatting.
|
Quote:
Thanks for the info, metaschima. |
There are two unmatched fis and $file never has a value assigned to it.
Here's the script with indentation Code:
#! /bin/sh |
Thank you, all, for your help. I've tried to make my edits based on your recommendations and here's what I've got so far. Also, because I forgot to put it earlier, the objective for this program is, "Write a shell script to locate executable files. This script takes a list of file names from the command line and determines which would be executed had these names been given as commands."
Code:
#! /bin/sh -xv |
It appears to work for me, with a few slight changes:
Line 15 Code:
$FINDALL = FALSE Code:
FINDALL=FALSE Code:
FINDALL = TRUE Code:
FINDALL=TRUE Code:
boygenius.sh python Code:
/usr/bin/python As grail points out though, you really should use this markup when pasting in code: [code] code goes here [/code] |
It is forgivable to have not done so the first time, but to ignore the request and do it again is not. Please go back and edit both posts and place your code in code tags.
I for one will not read something that is not formatted and as was pointed out by catkin, this simple process would have led you to find easily fixable issues. |
Regardless of the post formatting, the OP has shown adherence to the forum rules about posting homework, has shown effort of their own, and has been polite throughout. More posters should follow that example, in my opinion.
|
And I am not chiding them for their good effort, but unfortunately with my old eyes the lack of contrast and formatting makes it difficult to assist :(
|
Indent is also extremely useful in looking at code. If it's not in code tags, I tend to not look too closely at it.
|
Re the post #8 by notKlaatu, one point made is that spaces are "tokenizers" in bash and Posex-compliant variants. (bash, itself, is not Posix-compliant.) Thus A = B is three "tokens," whilst A=B is one "token," and interpreted as an implicit let command.
The other point is that $ is a substitution command, and a command can't occur as the target of an assignment. |
Thats a great explanation.
To add to that... the reason bash tokenizes them using spaces is a variable called IFS which defaults to " \t\n" easier read as "(space)(tab)(newline)" |
Quote:
|
All times are GMT -5. The time now is 08:12 PM. |