Search code examples
bashmacosresxslash

Replace slash in to empty in bash


Let's suppose I have this results:

CMD_VAL = 'test/'
echo $CMD_VAL
=> test/

echo "$CMD_VAL"|sed 's#/##g'
=>test

but,

PRO_VAL = "$CMD_VAL"|sed 's#/##g'
echo $PRO_VAL

this returns

=> "test/ is a directory"

How should it need to change in order to get the "test" into a variable as a string?


Solution

  • PRO_VAL=$(echo $CMD_VAL|sed 's#/##g')
    

    you need to echo first, "$CMD_VAL"|sed 's#/##g" will be run $CMD_VAL and pipe to sed,it's not correct.