Find the answer to your Linux question:
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 ...
  1. #1
    Just 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

  2. #2
    Linux 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

  3. #3
    Just 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?

  4. #4
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Post some lines of etc/sysconfig/network and an example of the desired output.

  5. #5
    Just 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...