Replacing string in linux using sed/awk based
问题 i want to replace this #!/usr/bin/env bash with this #!/bin/bash i have tried two approaches Approach 1 original_str="#!/usr/bin/env bash" replace_str="#!/bin/bash" sed s~${original_str}~${replace_str}~ filename Approach 2 line=`grep -n "/usr/bin" filename` awk NR==${line} {sub("#!/usr/bin/env bash"," #!/bin/bash")} But both of them are not working. 回答1: You cannot use ! inside a double quotes in BASH otherwise history expansion will take place. You can just do: original_str='/usr/bin/env