Let's say I have a path that looks like this:
/A/B/C/DIRECTORY/D/E/F
Now, what I want to achieve by changing the parameters is cutting off part of the path after DIRECTORY, regardless of where the DIRECTORY path is (A, B, C, etc., just mean random directory names).
After substitution:
/A/B/C/DIRECTORY
This is what I have tried so far:
#!/bin/bash if [[ $# < 1 ]] then echo "Usage: $0 DIRECTORY" fi CURRENT_DIRECTORY=$(pwd) DIRECTORY=$1 cd ${CURRENT_DIRECTORY%!(DIRECTORY)/*}
Obviously this does not work. I could implement this using awk or sed, but I am wondering if this is possible using only parameter replacements.
source share