Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-12-2010
Registered User
 

Join Date: Dec 2006
Posts: 236
Thanks: 52
Thanked 0 Times in 0 Posts
Help Needed with Shell Script Variable

ok, so, i want to do something like this where i store results of codings in a variable, but when i run it, it doesn' twork:


example


Code:
HOT=34
BOSS=`john=133
if [ "$john -eq 133 ] ; then
ADDIT=`expr 8 + 6`
case $HOT in
34) expr 4 + 5 ;; esac
fi`

it seems shell scripts have a problem with having `` occur more than once. does anyone know a way around this? i want to be able to execute another command or action within a `` .

i hope you understand what i'm asking.

Last edited by pludi; 03-12-2010 at 12:08 PM.. Reason: code tags, please...
Sponsored Links
    #2  
Old 03-12-2010
pludi's Avatar
pludi pludi is offline Forum Staff  
Cat herder
 

Join Date: Dec 2008
Location: Vienna, Austria, Earth
Posts: 5,486
Thanks: 38
Thanked 324 Times in 301 Posts
Yes, that's right, backticks can't be nested. Which is why just about any shell gives you a warning when running the syntax check (eg. 'ksh -n yourscript.sh') that backticks should be replaced by the $(...) construct, which is nestable.
Sponsored Links
    #3  
Old 03-12-2010
kshji's Avatar
Registered User
 

Join Date: Jun 2009
Location: Finland
Posts: 499
Thanks: 0
Thanked 36 Times in 36 Posts

Code:
#!/bin/somesh (bash,dash,ksh,sh,...)
HOT=34

############################
dosome()
{
john=133
if [ "$john" -eq 133 ]
then
        ADDIT=$((8 + 6))
        case "$HOT" in
                34) echo $((4 + 5)) ;;
        esac
fi
}

############################
BOSS=$(dosome)
echo "$BOSS"

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with Shell Script Needed infinity2030 Shell Programming and Scripting 1 03-06-2009 01:56 AM
help needed for a shell script revenna Shell Programming and Scripting 0 12-11-2008 01:33 AM
Help needed for Shell Script..... pulkit Shell Programming and Scripting 0 02-22-2008 06:25 AM
shell script Help Needed!! smallu UNIX for Dummies Questions & Answers 0 01-15-2008 07:40 PM
shell script help needed fastgoon Shell Programming and Scripting 3 07-17-2006 04:24 PM



All times are GMT -4. The time now is 03:40 AM.