return and exit (plus more questions about shell scripting)
hi
i am using unix bash.. please someone can explain me what is the different between return and exit? and i write "exit 1" is it exit from the program and also return 1? thanks alot |
exit is for forcing the termination of and specifying the exit status of scripts. return is used for defining the exit status of functions. Otherwise they pretty much work the same way. The number specifies the exit value passed back to the parent process.
Check out their entries in the BUILTINS section of the bash man page. |
hi
thanks alot, i have one more question when i try to define a new variable like: var="hello" its write to me a error message: "var=hello: Command not found." i also tried to write : var=hello (without " ") however it has the same problem... what is the right correct formula to define a new variable in bash? question 2: if i want to execute valgrind on my program valgirnd ./ prog 4 how can i do a script that check the output of the valgrind and diplay "V" when there is no error else display "0"? thanks alot i really appreciate it |
variable=value is the correct syntax. There can be no spaces around the equal sign.
A variable name can only have letters, numbers, and underscores (a-z,A-Z,0-9,_), and cannot start with a number. If the value is a simple word then it doesn't need quoting. But if it contains spaces or shell-reserved characters, then it needs to be quoted so that the command treats it as a single literal string. Code:
var1=foobar I recommend you read through this guide. It will cover all the basic things you need to know for bash scripting: http://mywiki.wooledge.org/BashGuide |
hi david
that is exacly what i did: "~/ws2>var=hello var=hello: Command not found. " i attached for you the exact lines in the program...i have no any spaces.. also, can you answer please my second question: question 2: if i want to execute valgrind on my program valgirnd ./ prog 4 how can i do a script that check the output of the valgrind and diplay "V" when there is no error else display "0"? thanks alot i really appreciate it |
hi
i also attached pic.. please help me..i really dont know what is the problem http://img853.imageshack.us/img853/1707/35233026.jpg Uploaded with ImageShack.us |
HI
i understand where am i wrong... please, someone can help me with this 2 questions: 1. if i want to execute valgrind on my program valgirnd ./ prog 4 how can i do a script that check the output of the valgrind and diplay "V" when there is no error else display "0"? 2. if i have a word "some description for the test@program_name@inout/file.in@inout/file.out " and i want to seperate the word beteen the @... how can i do it? thanks alot |
1. actually, the default convention is 0 = no error, so
Code:
valgrind ./prog 4 Code:
echo "some description for the test@program_name@inout/file.in@inout/file.out "|awk -F'@' '{print $1, $2, $3, $4}' http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ http://www.grymoire.com/Unix/Awk.html |
hi
thanks alot i want that the valgrind will have a input and the output will execute into $1 and the input is $1, so what i wrote is: valgrind ./"$2" 4 < $3 > $1 is this syntax right? thanks |
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.
Quote:
Quote:
Code:
$ IFS='@' read -a arrayname <<<'some description for the test@program_name@inout/file.in@inout/file.out' http://mywiki.wooledge.org/BashFAQ/100 Quote:
You generally cannot use the same file for both input and output redirection at the same time. You'll usually end up with an empty file! The Input and Output section of the BashGuide I gave above explains the general usage of redirections (and also the here string I used with the read command above). Note also that you should double-quote all of your variable expansions e.g. "$1". |
tnx you all
i have one more problem: i wrote a script "testAll" Code:
#!/bin/bash Code:
#!/bin/bash Code:
~/tmpdir>testAll tests.lst |
hi
i resolved all the problem in my scripts.. however, now i have another problem.. i wrote a script which perform valgrind check on a program and display "Memory X" when there is a memory leakage or another problem and display "Memory V" when there is no any problem the script run without any error however it allways display "memory V" even when i did a program which has a memory leakage... can someone help me please? Code:
#!/bin/bash |
That's because you are checking the success/failure of the valgrind prog.
If valgrind (itself) doesn't crash or otherwise fail (not your code; valgrind itself), then it will return zero, that's the *nix way. You probably need to parse the output instead to get what you want... |
ok thanks alot i solved the problem...thank you
now i encouter another problem...i wrote a script: Code:
#!/bin/bash Code:
~/tmpdir>testAll tests.lst for example the script need to cut the first filed in the file $1 like "helloworld" and then to execute some scripts on this program..however i dont know what is it not work for me? i will be really happy for advices thanks alot |
You need to read+digest those links in my post #8.
In particular (for this latest qn) concentrate on the syntax for a 'while' loop. Basically, you're not feeding anything input into it, so $line is undefined. You could amend the top of your script to Code:
#!/bin/bash |
All times are GMT -5. The time now is 05:38 AM. |