Bash: .bash_profile function
by DynV from LinuxQuestions.org on (#502N4)
For what I'm attempting to do, please see the echo that start with description (which should be bold) in the .bash_profile content
Code:function omit_amp {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: omit_amp <any command that--might--contain an ampersand (\'&\')>"
echo "Example: omit_amp wget --limit-rate=300k --wait=2 --random-wait https://ubuntuforums.org/showthread.php?t=1234567&p=89012345#post89012345"
echo "Description: omit_amp will run anything it gets as argument up to an ampersand, which it will omit and all that follows."
return 1
else
${1%%\&*}
fi
}there was also an example (which should be italicized), which should end up running
Quote:
It's my understanding, which is quite fresh/new, that a function in .bash_profile content would be a good way to go about it.
Well, from it having for content the above code, here's the terminal content of my attempt to run it
Quote:
which Quote:
was censoring (for my privacy).
Please let me know what I'm doing wrong or a better way to end up with what's in the description and example.
Thank you kindly
Update 1: While I'd be happy with the former, my ultimate goal is for only the last string to be applied the S&R (search & replace). So is there was an ampersand in the command name or options, it wouldn't matter, only if the last string, in the example (in an echo in the code), only the URL would be submitted to S&R.


Code:function omit_amp {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: omit_amp <any command that--might--contain an ampersand (\'&\')>"
echo "Example: omit_amp wget --limit-rate=300k --wait=2 --random-wait https://ubuntuforums.org/showthread.php?t=1234567&p=89012345#post89012345"
echo "Description: omit_amp will run anything it gets as argument up to an ampersand, which it will omit and all that follows."
return 1
else
${1%%\&*}
fi
}there was also an example (which should be italicized), which should end up running
Quote:
wget --limit-rate=300k --wait=2 --random-wait https://ubuntuforums.org/showthread.php?t=1234567 |
Well, from it having for content the above code, here's the terminal content of my attempt to run it
Quote:
me@me-computer:~$ omit_amp wget --limit-rate=300k --wait=2 --random-wait https://ubuntuforums.org/showthread....5#post89012345 [1] 15111 me@me-computer:~$ omit_amp: command not found |
me@me-computer |
Please let me know what I'm doing wrong or a better way to end up with what's in the description and example.
Thank you kindly
Update 1: While I'd be happy with the former, my ultimate goal is for only the last string to be applied the S&R (search & replace). So is there was an ampersand in the command name or options, it wouldn't matter, only if the last string, in the example (in an echo in the code), only the URL would be submitted to S&R.