AceAA
asked on
How can i set a Environment Variable in my Unix script ?
Below is the code that I have, where I need to replace a server name with the hostname of the box I logged into, can someone please help? The below script is not working as expected, I might be doing something correct, may be?
server=$(hostname)
echo $server
for file in $(find /home/ace/ -type f)
do
sed 's/acee123/$server/g' $file > $file.tmp
mv $file.tmp $file
done
server=$(hostname)
echo $server
for file in $(find /home/ace/ -type f)
do
sed 's/acee123/$server/g' $file > $file.tmp
mv $file.tmp $file
done
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the points, Ace, and good point about Solaris.
You're probably right because I think Solaris doesn't come with GNU sed, which is what has the '-i' switch. (Although you can install GNU sed if you want to.)
But I think Solaris ships with Perl, and that has the '-i' switch, so you can do things like:
Note, I've just realised that the following 2 commands won't necessarily return the same result:
You're probably right because I think Solaris doesn't come with GNU sed, which is what has the '-i' switch. (Although you can install GNU sed if you want to.)
But I think Solaris ships with Perl, and that has the '-i' switch, so you can do things like:
perl -i -pe 's/\Qacee123\E/$ENV{HOSTNAME}/' /home/ace/*
Note that single quotes are OK with this Perl solution.Note, I've just realised that the following 2 commands won't necessarily return the same result:
hostname
echo $HOSTNAME
So if they don't on your system, then you might need to change things a bit. Let me know if you want help with that.
ASKER
Thank you,