Sponsored Content
Top Forums UNIX for Dummies Questions & Answers assigning (numeric) command output to var tcsh Post 302230024 by drl on Thursday 28th of August 2008 12:22:23 PM
Old 08-28-2008
Hi.

Keeping in mind that:
Quote:
The `@' command permits
numeric calculations to be performed and the result assigned to a vari-
able. Variable values are, however, always represented as (zero or
more) strings.

-- excerpt from man tcsh
We can use the following little script:
Code:
#!/usr/bin/env tcsh

@ result = 31416 * 2
echo $result

exit

As a source to set a variable in a larger script:
Code:
#!/usr/bin/env tcsh

# @(#) s1       Demonstrate script result capture.

echo
echo "(Versions displayed with local utility version)"
sh -c "version >/dev/null 2>&1" && version tcsh
echo

echo " Nonce script:"
cat -n t1

echo
echo " Results:"
set var1 = `./t1`
echo " var1 is $var1"

exit 0

Producing:
Code:
% ./s1

(Versions displayed with local utility version)
tcsh 6.13.00

 Nonce script:
     1  #!/usr/bin/env tcsh
     2
     3  @ result = 31416 * 2
     4  echo $result
     5
     6  exit

 Results:
 var1 is 62832

Note that the odd quotes (`) are backtics, not straight single quotes. See the man page for other details ... cheers, drl

(The usual advice advocating the use of Bourne family shells as opposed to csh family applies here.)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning output of command to a variable

Hi, I'm trying to assign the output of a command to a variable and then concat it with another string, however, it keeps overwriting the original string instead of adding on to the end of the string. Contents of test.txt --> This is a test var1="`head -n 1 test.txt`" echo $var1 (This is a... (5 Replies)
Discussion started by: oma04
5 Replies

2. Shell Programming and Scripting

assigning command output to a shell variable

I have the sql file cde.sql with the below contents: abcdefghij abcwhendefothers sdfghj when no one else when others wwhen%others exception when others Now I want to search for the strings containing when others together and ceck whether that does not occur more than once in the... (2 Replies)
Discussion started by: kprattip
2 Replies

3. Shell Programming and Scripting

Assigning output of command to a variable in shell

hi, I want to assign find command result into some temporary variable: jarPath= find /opt/lotus/notes/ -name $jarFile cho "the jar path $jarPath" where jarPath is temporary variable. Can anybody help on this. Thanks in advance ----Sankar (6 Replies)
Discussion started by: sankar reddy
6 Replies

4. Shell Programming and Scripting

Assigning output of a command to variable

When I run time -p <command>, it outputs: real X.XX user X.XX sys X.XXwhere X.XX is seconds. How I can take just that first number output, the seconds of real time, and assign that to a variable? (9 Replies)
Discussion started by: jeriryan87
9 Replies

5. UNIX for Dummies Questions & Answers

Assigning the output of a command to a variable, where there may be >1 line returned?

Hello I am using unix CLI commands for the Synergy CM software. The command basically searches for a folder ID and returns the names of the projects the folder sits in. The result is assigned to a variable: FIND_USE=`ccm folder -fu -u -f "%name"-"%version" ${FOLDER_ID}` When the command... (6 Replies)
Discussion started by: Glyn_Mo
6 Replies

6. Shell Programming and Scripting

Assigning expression value to tcsh variables

Hi All, I have a tcsh script as: #!/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... (2 Replies)
Discussion started by: AB10
2 Replies

7. Shell Programming and Scripting

Assigning numeric values to variable

I have a code like this v_num=9 comp_num=39 if then echo "pass" fi echo "end" I am getting an error ksh: v_num=99 comp_num=39 if then echo "pass" fi echo "end" (3 Replies)
Discussion started by: swayam123
3 Replies

8. 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

9. Shell Programming and Scripting

Nawk command to output in var

Hi I have this command, which counts number of lines in a specific file and then prints it on screen.nawk 'NF{c++}END{print "Number of GPS coordinates in file: "c}' $filename I would like to have the output put into a variable, but can't seem to find the correct argument for it. How do I... (3 Replies)
Discussion started by: bulleteyedk
3 Replies

10. Shell Programming and Scripting

Expect - assigning UNIX command output to a variable

Hi, I'm writing a script that connects through ssh (using "expect") and then is supposed to find whether a process on that remote machine is running or not. Here's my code (user, host and password are obviously replaced with real values in actual script): #!/usr/bin/expect set timeout 1... (3 Replies)
Discussion started by: oseri
3 Replies
shells(4)							   File Formats 							 shells(4)

NAME
shells - shell database SYNOPSIS
/etc/shells DESCRIPTION
The shells file contains a list of the shells on the system. Applications use this file to determine whether a shell is valid. See getuser- shell(3C). For each shell a single line should be present, consisting of the shell's path, relative to root. A hash mark (#) indicates the beginning of a comment; subsequent characters up to the end of the line are not interpreted by the routines which search the file. Blank lines are also ignored. The following default shells are used by utilities: /bin/bash, /bin/csh, /bin/jsh, /bin/ksh, /bin/pfcsh, /bin/pfksh, /bin/pfsh, /bin/sh, /bin/tcsh, /bin/zsh, /sbin/jsh, /sbin/sh, /usr/bin/bash, /usr/bin/csh, /usr/bin/jsh, /usr/bin/ksh, /usr/bin/pfcsh, /usr/bin/pfksh, /usr/bin/pfsh, and /usr/bin/sh, /usr/bin/tcsh, /usr/bin/zsh. Note that /etc/shells overrides the default list. Invalid shells in /etc/shells may cause unexpected behavior (such as being unable to log in by way of ftp(1)). FILES
/etc/shells lists shells on system SEE ALSO
vipw(1B), ftpd(1M), sendmail(1M), getusershell(3C), aliases(4) SunOS 5.10 4 Jun 2001 shells(4)
All times are GMT -4. The time now is 06:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy