Someday I will understand bash var types. This isn't the day yet. I have the following code:
#!/bin/bash
FILES=( "monitor_api*" )
FILE="./"${FILES[0]}
echo $FILE
TFILE="./monitor_api_0.3a.tar.gz"
echo ${FILE:0:$(expr ${#FILE} - 3)}
echo ${TFILE:0:$(expr ${#TFILE} - 3)}
result:
./monitor_api_0.3a.tar.gz
./monitor_a
./monitor_api_0.3a.tar
- Why is a concatenation with an array element different than a simple string ?
- How can I make $FILE a string so I can remove the last 3 chars ?
- Is there a better way to remove .gz from $FILE var ?
I just want to remove .gz from the filename.
Edit
@DavidC.Rankin and @CharlesDuffy
The objective of this script is getting the first file in the dir that starts with monitor_api add a "./" prefix and remove .gz suffix.
I've tried {FILE:0: -3}, ${FILE:0:(-3) and ${FILE%.gz} and none worked. Also notice I want to concatenate "./" before the the filename. Here's the result when using them:
#!/bin/bash
FILES=( "monitor_api*" )
FILE=${FILES[0]}
SFILE="./"$FILE
echo $SFILE
echo ${SFILE:0:-3}
echo ${SFILE:0:(-3)}
echo ${SFILE%.gz}
result:
./monitor_api_0.3a.tar.gz
./monitor_a
./monitor_a
./monitor_api_0.3a.tar.gz