Article 4XVEC Bash scripting: how to handle ampersand in a string for a positional parameter?

Bash scripting: how to handle ampersand in a string for a positional parameter?

by
ziphem
from LinuxQuestions.org on (#4XVEC)
Hello all!

I'm really stumped on this. I've been having fun in my .bashrc with shell functions, including making one for a command "pull." But I'm having a hard time figuring out how to handle strings that include "&". For instance:

~]$ pull file domain.tr/1em121cww

works no problem.

But

~]$ pull file domain.tr/1em121cww&s3fs12kfs

does not.

I know the easy solution is on the command line to simply write

~]$ pull file "domain.tr/1em121cww&s3fs12kfs"

but it's not so easy when you have multiple filenames (making use of positional parameter "${@:2}").

Is there some other way of handling the ampersand in the shell function? I thought maybe with sed, but this ampersand creates an issue before the shell function runs. I also don't want to process (escape, quote) every bash input with ampersands - just what I use for the "pull" command.

Thanks a ton for any help!latest?d=yIl2AUoC8zA latest?i=hJ89nf_Pe9w:Tmq_cKik4xU:F7zBnMy latest?i=hJ89nf_Pe9w:Tmq_cKik4xU:V_sGLiP latest?d=qj6IDK7rITs latest?i=hJ89nf_Pe9w:Tmq_cKik4xU:gIN9vFwhJ89nf_Pe9w
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments