2

I want to replace old path variable to new one like this:

script_path=$(readlink -f "$0") #[/home/username/Desktop/script]
desktopfolder_old=/home/username/Desktop
desktopfolder_new=/home/username/NewOne
script_path_new=$(echo "$script_path" | sed -e "s/$desktopfolder_old/$desktopfolder_new/")

Because the bash script will be moved while it is running. But couldn't do it. What would it be like?

0

1 Answer 1

1

Those /s in the variables are going to totally mess up the sed "s/$var... after the var substitutions. The -e is also superfluous. Try instead:

script_path_new=$(echo "$script_path" | sed "s|$desktopfolder_old|$desktopfolder_new|")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.