Bash String Manipulation – Continuous String Manipulation in Bash

bashshellshell-scriptstring

#!/bin/bash

FILE="$(basename "$1")"
FILE="${FILE/%.jpeg/.jpg}"

Is there anyway to glue these two lines together into a one-liner?

Best Answer

FILE=$(basename "${1/%.jpeg/.jpg}") worked for me.

test:

bash-$ ./test.sh /tmp/foo.jpeg
foo.jpg

script contents:

bash-$ cat test.sh 
#!/usr/bin/bash

FILE=$(basename "${1/%.jpeg/.jpg}")

echo "$FILE"
Related Question