I'm new to bash, but I had to write a simple script to archive things:
ARCHIVE_FOLDER=".archive/"
TO_ARCHIVE="folders.txt"
TO_IGNORE="ignore.txt"
mkdir -p $ARCHIVE_FOLDER
while read t_arc; do
EXCLUDE_STRING=" "
while read ig_l; do
while read found_exc; do
EXCLUDE_STRING="${EXCLUDE_STRING} --exclude ${found_exc}"
done < find $t_arc -name $ig_l
done < TO_IGNORE
tar -czf "${ARCHVE_FOLDER}/${t_arc}.tar.gz"
done < TO_ARCHIVE
It looks quite simple, but I get syntax error when using variables which are defined in "while read" construction:
./archive.sh: line 12: syntax error near unexpected token `${t_arc}'
./archive.sh: line 12: ` done < find ${t_arc} -name ${ig_l}'
Apparently, I can't even print them:
while read t_arc; do
EXCLUDE_STRING=" "
printf "%s\n" $t_arc # prints noting
What am I doing wrong here?
read's from that script, you will need to use a differentfdfor the 2 of them. Also add a shebang and paste your script at shellcheck.net for more help