Results 1 to 2 of 2
Hi,
I need to modify some text in a sh file as follows and am not sure about the syntax. I have read thru a few tutorials, but I haven't ...
- 03-19-2008 #1Just Joined!
- Join Date
- Mar 2008
- Posts
- 3
bash script text manipulation
Hi,
I need to modify some text in a sh file as follows and am not sure about the syntax. I have read thru a few tutorials, but I haven't found what I need.
MY_HOSTNAME=`/bin/hostname -s`
MY_NFS1=$MY_HOSTNAME + .bw.mycampus.edu
MY_DHCPD1=$MY_HOSTNAME + .bw.mycampus.edu
MY_TFTP1=$MY_HOSTNAME + .bw.mycampus.edu
where the resulting environment variables will be:
MY_HOSTNAME=myhostname (without fqdn)
MY_NFS1=myhostname.bw.mycampus.edu
MY_DHCPD1=myhostname.bw.mycampus.edu
MY_TFTP1=myhostname.bw.mycampus.edu
I realize that this is probably really easy but I am new to scripting and not sure how to append the text as needed.
Thanks!
gabrielle64
- 03-19-2008 #2
As you've probably seen, Bash takes most of the variable declaration to be rather literal. Following that thought, what you want is:
In this case, it works because '.' is an invalid character in a variable name, so it knows to stop treating this like a variable. Let's suppose that we wanted to instead do $MY_HOSTNAME and then 'hello'. We would do:Code:MY_HOSTNAME=`/bin/hostname -s` MY_NFS1=$MY_HOSTNAME.bw.mycampus.edu MY_DHCPD1=$MY_HOSTNAME.bw.mycampus.edu MY_TFTP1=$MY_HOSTNAME.bw.mycampus.edu
Here, we specifically tell it how much of this is the variable name.Code:${MY_HOSTNAME}helloDISTRO=Arch
Registered Linux User #388732


Reply With Quote