Remove line breaks in Bourne Shell from variable

后端 未结 4 1790
猫巷女王i
猫巷女王i 2021-02-07 07:45

In bourne shell I have the following:

VALUES=`some command that returns multiple line values`

echo $VALUES

Looks like:

\"ONE\"         


        
4条回答
  •  野性不改
    2021-02-07 08:03

    Another method, if you want to not just print out your code but assign it to a variable, and not have a spurious space at the end:

    $ var=$(tail -1 /etc/passwd; tail -1 /etc/passwd)
    $ echo "$var"
    apache:x:48:48:Apache:/var/www:/sbin/nologin
    apache:x:48:48:Apache:/var/www:/sbin/nologin
    $ var=$(echo $var)
    $ echo "$var"     
    apache:x:48:48:Apache:/var/www:/sbin/nologin apache:x:48:48:Apache:/var/www:/sbin/nologin
    

提交回复
热议问题