How to use SED without a file with env var?

Is it possible to replace a thing in env var with SED?

$ a='aoeua' $ sed ' s@a @ o@g ' <$a bash: aoeua: No such file or directory $ env|grep "SHELL" SHELL=/bin/bash 

The output I want

 ooeuo 

replacing each a with 'aoeua' with o .

+7
source share
2 answers

Use echo:

 $ echo "$a" | sed ' s@a @ o@g ' 

In bash, you can also perform simple substitutions with the syntax ${parameter/pattern/string} . For example:

 $ v='aoeua' $ echo ${v/a/o} ooeua 

Note that this only replaces the first occurrence of the pattern.

+10
source

This might work for you:

 a='aoeua' sed ' s@a @ o@g ' <<<$a ooeuo 

<<<$a - here is the string

+6
source

All Articles