05-10-2006
Yeah I didn't phrase my question the way I wanted to. Let me try again.
Given the following:
----------------------
foreach var (t v w)
grep $var ./file > ./newfile
set ${var}temp = `awk '{print $2}' ./newfile`
now this is where I need help
how can I echo each variable with only one echo statement, essentially, do:
echo $ttemp $vtemp $wtemp
But doing this with alot of variables, creates a long script, and is not very efficient.
I've tried the following
echo ${$var}temp, this doesn't work
end
Hopefully this makes more sense than before.
Thanks in advance.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
With the if statement:
if
How can I make it so it accepts a wildcard after the ${CURR_DAY_MONTH} variable?
Putting
a -f /webtrends/SUN/mrw2/access.${CURR_DAY_DAY}${CURR_DAY_MONTH}*
won't work, right? I think I need some kind of special character so it knows the wildcard is... (3 Replies)
Discussion started by: LordJezo
3 Replies
2. Shell Programming and Scripting
I am just wondering if it's possible to refer to variables within a sed statement as follows:-
cat $file | sed -e 1's/$oldtext/$newtext/' > $file
as when I run the script, the variables are not recognised and nothing happens..??
Thanks (5 Replies)
Discussion started by: sirtrancealot
5 Replies
3. Shell Programming and Scripting
Ok, So up front I'm going to say that I'm a very elementary scripter, and I tend to use tools I don't fully understand, but I shotgun at something until I can get it to work...that said, I can't for the life of me understand why I can't get this to go down the way I want it to.
The goal:
-to... (6 Replies)
Discussion started by: DeCoTwc
6 Replies
4. Shell Programming and Scripting
meas is a shell variable, and this works perfectly fine for me:
awk -v var=$meas -F, '$1==var' /abcd/efgh.txt > temp1.csv
However, i want to introduce another shell variable, named, defnfile in the statement, in place of hardcoded path for efgh.txt like:
awk -v var=$meas -F, '$1==var'... (3 Replies)
Discussion started by: indianjassi
3 Replies
5. Shell Programming and Scripting
is it possible to call a variable in a case statement, for example
lsmonth=Jan|Feb
l |while read ans
do
mymonth=`echo $ans |awk '{print $6}'`
case $mymonth in
$lsmonth) echo do something
;;
*) echo do something else
;;
esac
done
I want to use $lsmonth... (8 Replies)
Discussion started by: gefa
8 Replies
6. Shell Programming and Scripting
kindly find below:-
var="'(]\\{}\$\""
echo $var # it wil give this '(]\{}$"
echo "$var" # '(]\{}$" Doesn't make a difference why???.
if we set IFS to '\' also the below happens
IFS='\'
echo $var # '(] {}$" \ converted to space. Why? weird!!
echo "$var"... (3 Replies)
Discussion started by: ahmad.diab
3 Replies
7. UNIX for Dummies Questions & Answers
HI,
I have 5 variables var1, var2, var3, var4 and var5
I need to initialize all of them to zero.
Is there a way to do it in a single line
something like this
var1=var2=var3=var4=var5=0.
I am unable to achieve this.
What is going wrong? (2 Replies)
Discussion started by: paku
2 Replies
8. UNIX for Dummies Questions & Answers
Hi,
i can print 2nd, 4th and 6th columns in a file using the shell command:
awk -F "|" '{print $2 $4 $6}' file1.txt
Now, the position and number of columns can be variable and from a variable POSLIST
So let's say
POSLIST='$2 $4 $6'
when i use the command:
a)
awk -F "|" '{print... (2 Replies)
Discussion started by: ysrini
2 Replies
9. Shell Programming and Scripting
#!/bin/bash
#timetest
TIMENOW="$(date)"
T1=12:00:00
echo $TIMENOW >timenow
cat timenow |cut -f4 -d' ' >time1
T2=$(sed -n "${1}p" time1)
echo "T1 = " $T1
echo "T2 = " $T2
if then
echo $T1
else
echo $T2
fi
I thought scripting was simple! So why does this script result in:
T1 =... (4 Replies)
Discussion started by: habuchas
4 Replies
10. Shell Programming and Scripting
Environment:
BASH version: GNU bash, version 3.2.51(1)-release (sparc-sun-solaris2.10)
Copyright (C) 2007 Free Software Foundation, Inc.
OS: Oracle Solaris 10 9/10 s10s_u9wos_14a SPARC
Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
... (4 Replies)
Discussion started by: os2mac
4 Replies
escape(1) Mail Avenger 0.8.3 escape(1)
NAME
escape - escape shell special characters in a string
SYNOPSIS
escape string
DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result.
EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string:
$ var='; echo gotcha!'
$ eval echo hi $var
hi
gotcha!
$
Using escape, one can avoid executing the contents of $var:
$ eval echo hi `escape "$var"`
hi ; echo gotcha!
$
A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For
example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient:
#!/bin/sh
formail -x to -x cc -x resent-to -x resent-cc
| fgrep "$1" > /dev/null
&& exit 0
echo "<$1>.. address does not accept blind carbon copies"
exit 100
To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt
script:
bodytest reject_bcc `escape "$RECIPIENT"`
SEE ALSO
avenger(1),
The Mail Avenger home page: <http://www.mailavenger.org/>.
BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells.
AUTHOR
David Mazieres
Mail Avenger 0.8.3 2012-04-05 escape(1)