I encountered some unexpected behaviour of my bash
. This is my in-/output:
nepumuk@pc:~$ type URL
URL is a function
URL ()
{
echo -e "${_//%/\\x}"
}
nepumuk@pc:~$ URL %2f
URL
nepumuk@pc:~$ URL %2f
/
nepumuk@pc:~$ URL %2F
/
nepumuk@pc:~$ type URL
URL is a function
URL ()
{
echo -e "${_//%/\\x}"
}
nepumuk@pc:~$ URL %2f
URL
nepumuk@pc:~$ URL %2f
/
nepumuk@pc:~$ URL %2f
/
nepumuk@pc:~$ URL %2f
/
nepumuk@pc:~$ URL %2f
/
nepumuk@pc:~$ URL %2f
/
The corresponding part in the bash function file is:
url() {
: "${*//+/ }"
echo -e "${_//%/\\x}"
}
export -f url
URL() {
echo -e "${_//%/\\x}"
}
export -f URL
During testing I changed the content of URL
to echo -e "${@//%/\\x}"
to see wether something changes. Opening a new terminal (emulator?) window with the latter being used, I get
nepumuk@pc:~$ URL %2f
/usr/share/bash-completion/bash_completion
nepumuk@pc:~$ URL %2f
/
nepumuk@pc:~$ URL %2f
/
Although I could fully reproduce (and use the former for it gives the desired output), but I'd be happy having an explanation.
$_
is expanding to the argument of the previous command - so not the "same input"$1
would be the first argument to the function itself, and"$@"
would be all of them. It should work ok withecho -e "${@//%/\\x}"
, the output you show doesn't seem to match that expansion