![]() |
compare strings in shell scripting
Hi all.....
Code:
#!/bin/shcan anyone tell me what is wrong in the above script... it is always echoing "Scratchbox is not installed in the system......" eventhough the output of the command apt-cache show scratchbox-core | grep "Status" | awk '{print $4}' is "installed" |
Code:
i= apt-cache show scratchbox-core | grep "Status" | awk '{print $4}'Code:
i=$(apt-cache show scratchbox-core | grep Status | awk '{print $4}') |
oh..wow.. thanks a lot colucix... :)
and can u please tell me what is the difference between the first one (the one i did ) and the second one (one suggested by u) ??? i am a newbie to scripting... i will post back if i have some problems in scripting.. thanks again... :) |
again another problem.. why this logical or inside the shell script is not working... ??? !!!
if [("$j" != "$cpu") -o ("$j" != "$libs")] it is telling syntax error near unexpected token `"$j"' |
Try:
Code:
if [ "$J" != "$cpu" ] || [ "$J" != "$libs" ]; then |
Or:
Code:
case "$J" in |
hey...matthewg42 thanks a lot ... :)
i am really confused here.... why scripting is like this.. just because of spacing it gives me different output and error... ??? !!!! really confused.. is there a standard way of formatting these expressions.. where can i get all these info... ? and i tried even without the semicolon(;) at the end of the if statement.. it is working without semicolon also... why is like this ?? |
Shell scripting syntax is a little bit clunky compared to other languages, partly because the parser is a single-pass affair, rather than multi-pass parsers used in other languages. But like anything, only you've learned it, it has it's moments.
Perhaps you'd do better to start with a tutorial rather than expecting to be able to implement your script without learning the basics. |
ya sure matthewg42... thanks... :)
|
Quote:
i=`apt-cache show scratchbox-core | grep "Status" | awk '{print $4}'` |
The original conversation is from 2007(!); please don't bring up old posts like that.
|
| All times are GMT -5. The time now is 08:25 PM. |