Assigning expression value to tcsh variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assigning expression value to tcsh variables
# 1  
Old 10-19-2010
Question Assigning expression value to tcsh variables

Hi All,

I have a tcsh script as:

Code:
#!/usr/bin/csh -x

set packsName=$(awk -F'[=.]' '/^execute.*=true/{print $2}' ExecutePacks.config)

for var in $packsName
do
echo "printed $var"
done

I want to assign the value which is returned by awk function to the variable called packsName.
How do I do that?

One more thing,
Is syntax of for loop in 'ksh' and 'tcsh' different?

Thanks in advance!

Last edited by Scott; 10-19-2010 at 08:16 AM.. Reason: Please use code tags
# 2  
Old 10-19-2010
Hi.

I don't know about tcsh, but AFAIK csh does not support $(...) command substitution. Use back-quotes (` ... `) instead.

The for-loop syntax in csh is not the same as in ksh.

Code:
foreach var($packsName)
  echo "printed $var"
end

# 3  
Old 10-19-2010
Thanks it also worked in tcsh!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Tcsh command for assigning output of awk to variable

Hi I have a text file with 2 values and I am trying to assign each value to a variable and then write those to text files. So if the textfile is data.txt with 2 values x and y I want to assign mean=x, and stdev=y and then write these out in text files alongwith the id ($id has already been... (6 Replies)
Discussion started by: violin
6 Replies

2. Solaris

Assigning an expression to a variable in shell script

i am trying to assign the following expression to a variable in Unix shell script and want to use that variable in some other expression. But unable to get the required thing done. Please help with this.... This is the expression which i want to provide as input the variable date '+%y:%m:%d' |... (3 Replies)
Discussion started by: ssk250
3 Replies

3. Shell Programming and Scripting

Assigning Variables

Hi, Can the below be clarified please. i just want to know what is the difference between the two ways of assigning variables as mentioned below. export SRC_TBL=${SRC_TBL-"MMA_COPAY_PLN_FACT_STG"} export SRC_TBL="MMA_COPAY_PLN_FACT_STG" thanks in advance :) Arun (1 Reply)
Discussion started by: Arun Mishra
1 Replies

4. Shell Programming and Scripting

Assigning variables

i have variables RECIPIENTS_DEVL,RECIPIENTS_UACC,RECIPIENTS_PROD i have a case statement to get the phase variable: case ${WMD_UPHASE1} in u) WMD_UPHASE4=UACC;; i) WMD_UPHASE4=DEVL;; p) WMD_UPHASE4=PROD;; d) WMD_UPHASE4=DEVL;; *) WMD_UPHASE4=DEVL;; esac I am unable to... (3 Replies)
Discussion started by: Arun Mishra
3 Replies

5. Shell Programming and Scripting

assigning value of a expression to a variable

eval echo \$tts_space_name$count i m getting output of this stmnt as 'TBS_ADOX_EXTR3' but, I m not able to assign this value to a variable . i tried export j=`eval echo \$tts_space_name$count` eval j= `eval echo \$tts_space_name$count` and when i do echo $j ... i get o/p as 1 or 2... (1 Reply)
Discussion started by: Gl@)!aTor
1 Replies

6. Shell Programming and Scripting

variables not assigning in a function

Hi GUYS, I have function. I am assigning a line count to count variable. But it is throwing an error at this line. function_recur (){ #file being created in this function lenth = `wc -l function_outpu.dat`; echo $lenth; } this is the error i got rec.ksh: lenth: not found. ... (3 Replies)
Discussion started by: mac4rfree
3 Replies

7. UNIX for Dummies Questions & Answers

assigning (numeric) command output to var tcsh

Hello, I'm trying to assign a numeric value that is returned from one of my programs to a variable in tcsh. I want to do: @ r10 = './my_prog file 35' where ./my_prog file 35 returns a decimal value, but this doesn't work. How do I achieve the desired result? Janet (4 Replies)
Discussion started by: psran
4 Replies

8. UNIX for Dummies Questions & Answers

Assigning evaluated expression to a variable

Hello, Could you please let me know what is the problem here.. 28:var1="SERVER_$j" 29:eval $var1=`grep "^DBSERVER=" "$i" |cut -d"=" -f2` i get this error: syntax error at line 29 : `|' unexpected Thanks for your quick response..This is urgent..pls.. Regards Kaushik (5 Replies)
Discussion started by: kaushikraman
5 Replies

9. Shell Programming and Scripting

Help in Setting Environment variables in TCSH

Hello All, I am writing a script to set some environment variables which are required for a particular application. I understand that the environment variables set by Shell script can, at the max, be valid for the session. They will have to be set again once the session is closed and re-opened.... (1 Reply)
Discussion started by: kssandeep
1 Replies

10. UNIX for Dummies Questions & Answers

assigning variables

Before I even attempt this, is it possible to grep for a pattern, maybe a partial sentence like "go to page 3", assign that to a variable and then use awk or something to pull out the 3 and assign it to a variable? So first I would have Gotopg = "go to page 3" then page = 3 (9 Replies)
Discussion started by: k@ssidy
9 Replies
Login or Register to Ask a Question