I am trying to cut off all occurrences of a character from the end of a string.
The test script I came up with is:
#!/bin/bash
Input="/tmp/blah/bloh/////////////"
Desired="/tmp/blah/bloh"
cut='/'
result=${Input%%+(${cut})}
echo " Input: ${Input}"
echo "Expected result: ${Desired}"
echo " Result: ${result}"
echo "---------------------------------------"
echo -n " Outcome: "
[ "${Desired}" = "${result}" ] && echo "Success!" || echo "Fail!"
Running this script via bash /tmp/test.sh gives the following output:
Input: /tmp/blah/bloh/////////////
Expected result: /tmp/blah/bloh
Result: /tmp/blah/bloh/////////////
---------------------------------------
Outcome: Fail!
However, if I copy and paste the entire thing in my console I get the expected result of /tmp/blah/blah
What is going on here?
#!/bin/bashwith#!/bin/bash -i;)