2

Ubuntu 16.04

Even thou the output of for client in */; do doesn't produce a trailing slash, the trailing slash appears if I echo the variable $client while performing a time test on the file, within the loop.

cd "$wDir"
for client in */; do
   cd "$wDir"/"$client";

   #-- check to see if any .csv files exists
   if ls *.csv &>/dev/null; then
      for csvfile in *.csv; do
         if test $(find "$csvfile" -mmin +2880); then
            echo "$client has files older than 2 days ..." >> "staleFtpAccts"
         fi
      done
   fi
done

When I execute the script, a / is placed after the $client variable like so:

root@me /home/frank # bash script.sh
Start ...
000029_000020/ has files older than 2 days ...
#--
Finished ...

Start ...
000033_000040/ has files older than 2 days ...
#--
Finished ...

Start ...
000033_000041/ has files older than 2 days ...
#--
Finished ...

Start ...
000033_000042/ has files older than 2 days ...
#--
Finished ...

Start ...
000033_000043/ has files older than 2 days ...
#--
Finished ...

This is the result I am after ...

root@me /home/frank # bash script.sh
Start ...
000029_000020 has files older than 2 days ...
#--
Finished ...

Start ...
000033_000040 has files older than 2 days ...
#--
Finished ...

Start ...
000033_000041 has files older than 2 days ...
#--
Finished ...

Start ...
000033_000042 has files older than 2 days ...
#--
Finished ...

Start ...
000033_000043 has files older than 2 days ...
#--
Finished ...
0

1 Answer 1

7

Try this parameter expansion :

echo "${client%/}"

so

echo "${client%/} has files older than 2 days ..."

Parameter Expansion expands parameters: "$foo", "$1". You can use it to perform string or array operations: "${file%.mp3}", "${0##*/}", "${files[@]: -4}". They should always be quoted. See: http://mywiki.wooledge.org/BashFAQ/073 and "Parameter Expansion" in man bash. Also see http://wiki.bash-hackers.org/syntax/pe.

1
  • Well appreciated Gilles. Commented Mar 25, 2018 at 14:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.