Results 1 to 5 of 5
I'm building a script for my place of employment. The next step in it is checking what the user input was. Determining if they added a part in there or ...
- 05-23-2010 #1Just Joined!
- Join Date
- Jul 2009
- Posts
- 24
How to check command line for a word
I'm building a script for my place of employment. The next step in it is checking what the user input was. Determining if they added a part in there or not.
The script prompts for a hostname. Hostnames are localhost.localdomain. Now, I want the script to check to see if they put localdomain and if they did, not to add the domain to the /etc/sysconfig/network, but just what they entered.
So say the user inputs:
Please enter hostname: Localhost
read HOSTNAME;
sed -i 's/localhost.localdomain/$HOSTNAME.localdomain/g' /etc/sysconfig/network
Please enter hostname: localhost.localdomain
read HOSTNAME;
sed -i 's/localhost.localdomain/$HOSTNAME/g' /etc/sysconfig/network
How do I have the script check $HOSTNAME to see if they put in .localdomain or not?
Let me know if I need to explain it better..
Thanks
- 05-23-2010 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Use double quotes, single quotes prevent the shell to expand variables:
Code:sed -i "s/localhost.localdomain/$HOSTNAME.localdomain/g" /etc/sysconfig/network
- 05-23-2010 #3Just Joined!
- Join Date
- Jul 2009
- Posts
- 24
But what if they added .localdomain in their input? I don't want to put it in there again. Is that what " " do?
- 05-23-2010 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Post some lines of etc/sysconfig/network and an example of the desired output.
- 05-23-2010 #5Just Joined!
- Join Date
- Jul 2009
- Posts
- 24
That's almost irrelevant. I'm trying to have the script check the command line for a word.


Reply With Quote