Help Needed with Shell Script Variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help Needed with Shell Script Variable
# 1  
Old 03-12-2010
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 01:08 PM.. Reason: code tags, please...
# 2  
Old 03-12-2010
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.
# 3  
Old 03-12-2010
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"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script - help needed

I want to take out the Z1 value from the lscfg outpu and use the below command to get it lscfg -vl hdisk0 | grep "Device Specific.(Z1)" | awk -F. '{print $NF}' # lscfg -vpl hdisk0 . . Device Specific.(Z0)........0000063268181002 Device Specific.(Z1)........020064a . And it works,... (2 Replies)
Discussion started by: moorthikv
2 Replies

2. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

3. Shell Programming and Scripting

Needed shell script for the following

hi all, i want the script for the following my input is date mm-dd-yyyy i.e 1-4-2012(it doesn't have zeros in the input ,in output it should append zeros and should print the output as defined below) my output should be 2012-04-01(yyyy-dd-mm) if my input is 11-14-2012 then my should be... (7 Replies)
Discussion started by: hemanthsaikumar
7 Replies

4. UNIX for Dummies Questions & Answers

Help needed with Shell script

Hi I want a script which should basically do 1. If the size of the file is 0kb, send email to some list od ppl 2. if the size of the file is other than 0kb send email to someother list... Pls help (2 Replies)
Discussion started by: win4luv
2 Replies

5. Shell Programming and Scripting

Help Needed on shell script

#!/bin/sh #Displaying every argument while ; do echo Moving file $0; shift; done exit 0; For the above script i get the below o/p when 2 arguments are passed when invoking the script dmlFileCopy.sh: line 3: Can you let me know how to rectify the error? (2 Replies)
Discussion started by: Anand86
2 Replies

6. Shell Programming and Scripting

Shell script help is needed

I have a file test.txt and i need to grep pattern "A.17" from that file. I know cat test.txt | grep A.17 will return the pattern, but it is returing like # VERSION=A.17 How can i take only A.17 from this if A.17 is found, ... do something if not found ... do something Please... (11 Replies)
Discussion started by: Renjesh
11 Replies

7. Shell Programming and Scripting

Help needed in shell script

i am trying to read an existing xml file and find an element in the xml file of following format <home.dir value="/local/mnt/homes/docs"/> I am trying to take a command line argument to my shell script whose value should replace /local/mnt/homes/docs in xml document. Can you please point me how... (3 Replies)
Discussion started by: viswas
3 Replies

8. Shell Programming and Scripting

Help with Shell Script Needed

Hi all, I'm a newbie. I'm thinking of making a shell script which will list a directory for *.csv files and merge all the files into a single file called data.csv. However, i have no idea how to. What i do currently is to manually issue the following command to merge multiple CSV files into... (1 Reply)
Discussion started by: infinity2030
1 Replies

9. UNIX for Dummies Questions & Answers

shell script Help Needed!!

Hi guys-- Here is the interesting problem.. I have a folder, which has a couple of xml files like ( could be anywhere under the sub folders) ABCD_NA.xml XAYSGD_SC.xml CBV_CA.xml etc I need to peek in each of these xml's and see that the pattern before the _ and after the _ are there... (0 Replies)
Discussion started by: smallu
0 Replies

10. Shell Programming and Scripting

shell script help needed

I am trying to query a table having 3 columns, the third column is a field of varchar(1024) with a SQL string in it. I am using cut command to split out the three fields into three variables. I do a db2 command to extract the data into a file. My problem is with the third field having the SQL... (3 Replies)
Discussion started by: fastgoon
3 Replies
Login or Register to Ask a Question