Bash command as variable

前端 未结 5 1050
一个人的身影
一个人的身影 2021-01-24 02:43

I am trying to store the start of a sed command inside a variable like this:

sedcmd=\"sed -i \'\' \"

Later I then execute a command like so:

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-24 03:35

    Not exactly sure what you're trying to do, but my suggestion is:

    sedcmd="sed -i "
    $sedcmd s/$orig_pkg/$package_name/g $f
    

    You must set variables orig_pkg package_name and f in your shell first.

    If you're replacing variable names in a file, try:

    $sedcmd s/\$orig_pkg/\$package_name/g $f
    

    Still f must be set to the file name you're working on.

提交回复
热议问题