Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Shell Script help
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- Re: Shell Script help
Shell Script help
06-03-2008 3:10 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I have a shell script:
./compilejar.sh >> jar.txt
grep -c "BUILD SUCCESSFUL" jar.txt
cnt="$1"
echo ${cnt}
if [[ "$cnt" -eq 0 ]]; then
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!BUILD FAILED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo JAVA COMPILE FAILED
exit
fi
however it always seem to be getting caught even when the echo of cnt is 1, denoting as succesful build.
Can anyon offer any advice as to what might be wrong as i can't see it.
Thanks a lot.
./compilejar.sh >> jar.txt
grep -c "BUILD SUCCESSFUL" jar.txt
cnt="$1"
echo ${cnt}
if [[ "$cnt" -eq 0 ]]; then
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!BUILD FAILED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo JAVA COMPILE FAILED
exit
fi
however it always seem to be getting caught even when the echo of cnt is 1, denoting as succesful build.
Can anyon offer any advice as to what might be wrong as i can't see it.
Thanks a lot.
Customer / Moderator
If it helped click the thumb
If it fixed it click 'This fixed my problem'
If it helped click the thumb
If it fixed it click 'This fixed my problem'
3 REPLIES 3
Re: Shell Script help
06-03-2008 3:40 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I think you're meaning to set $cnt != 0 if grep finds the string. but at the moment you're not testing the exit code from grep so isn't cnt set on every run so it will != 0 ?
(i can't program for toffee by the way so i'm likely talking out of my fundament)
(i can't program for toffee by the way so i'm likely talking out of my fundament)
Re: Shell Script help
06-03-2008 8:40 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
First $1 does not give you the output from the grep command.
$? will give you the return code (not the output) from the last command. In the case of grep, it will return 0 if it found a match and 1 if it does not.
So your code should be:
./compilejar.sh >> jar.txt
grep -c "BUILD SUCCESSFUL" jar.txt >/dev/null
if [ "$?" -eq 1 ]; then
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!BUILD FAILED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo JAVA COMPILE FAILED
exit
fi
$? will give you the return code (not the output) from the last command. In the case of grep, it will return 0 if it found a match and 1 if it does not.
So your code should be:
./compilejar.sh >> jar.txt
grep -c "BUILD SUCCESSFUL" jar.txt >/dev/null
if [ "$?" -eq 1 ]; then
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!BUILD FAILED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo JAVA COMPILE FAILED
exit
fi
Re: Shell Script help
06-03-2008 8:52 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
wow, does that mean i was at least somewhere near the right track Peter?
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- Re: Shell Script help