LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   sed command (https://www.linuxquestions.org/questions/programming-9/sed-command-384731/)

rharris72 11-19-2005 05:56 PM

sed command
 
i am trying to help a buch of guys edit files for gaming servers using questions user input then sed command but if they put a space into the sting it fails can any one help

echo "Please give server name "

read name
sed s/clan/$name/g server.cfg > cfg.cfg

if they dont type spaces its fine

as soon as say they type "clan server"

the script fails is there a way of letting them use spaces
as bit of a pain in the rear can only use one word or a long sentence with no spaces

shanenin 11-19-2005 06:41 PM

you need to enclose your sed command in quotes
Code:

sed "s/clan/$name/g" server.cfg > cfg.cfg

rharris72 11-20-2005 02:46 AM

thanks such a simple answer and work boy do i feel stupid lol

/bin/bash 11-20-2005 05:21 AM

http://main.rtfiber.com.tw/~changyj/sed/

eddiebaby1023 11-20-2005 07:57 AM

Quote:

Originally posted by rharris72
thanks such a simple answer and work boy do i feel stupid lol
Don't feel stupid, lots of people don't seem to know how to use quotes - they just throw them in until things seem to work. Time invested in learning how to use single and double quotes properly will repay you many times over in saved time when you get it right first time. As an example, see the difference in the following:
Code:

VAR="a    b          c                        d"
echo $VAR
echo "$VAR"
echo '$VAR'


rharris72 11-20-2005 02:24 PM

ok thanks do you also know how i can soft or hard link folders so i can have say one folder with main game files in and another with the links in to the folder plus the server.cfg file for there individual server

i know im asking alot but hey i'm learning fast

thanks

/bin/bash 11-20-2005 08:26 PM

Quote:

do you also know how i can soft or hard link folders so i can have say one folder with main game files in and another with the links in to the folder plus the server.cfg file for there individual server
lndir
Code:

NAME
      lndir  -  create a shadow directory of symbolic links to another direc-
      tory tree

SYNOPSIS
      lndir [ -silent ] [ -ignorelinks ] [ -withrevinfo ] fromdir [ todir ]

DESCRIPTION
      The lndir program makes  a  shadow  copy  todir  of  a  directory  tree
      fromdir,  except  that  the shadow is not populated with real files but
      instead with symbolic links pointing at the real files in  the  fromdir
      directory tree.  This is usually useful for maintaining source code for
      different machine architectures.  You create a  shadow  directory  con-
      taining  links  to the real source, which you will have usually mounted
      from a remote machine.  You can build  in  the  shadow  tree,  and  the
      object files will be in the shadow directory, while the source files in
      the shadow directory are just symlinks to the real files.



All times are GMT -5. The time now is 08:10 AM.