How to remove the trailing slash from a variable which defines a directory from a time test output
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
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 ...
bash delete slash
add a comment |Â
up vote
1
down vote
favorite
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 ...
bash delete slash
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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 ...
bash delete slash
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 ...
bash delete slash
edited Mar 23 at 14:52
asked Mar 23 at 14:50
needtoknow
1286
1286
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
Try this posix 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.
Well appreciated Gilles.
â needtoknow
Mar 25 at 14:18
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Try this posix 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.
Well appreciated Gilles.
â needtoknow
Mar 25 at 14:18
add a comment |Â
up vote
4
down vote
accepted
Try this posix 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.
Well appreciated Gilles.
â needtoknow
Mar 25 at 14:18
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Try this posix 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.
Try this posix 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.
edited Mar 23 at 16:20
answered Mar 23 at 14:52
Gilles Quenot
15.3k13448
15.3k13448
Well appreciated Gilles.
â needtoknow
Mar 25 at 14:18
add a comment |Â
Well appreciated Gilles.
â needtoknow
Mar 25 at 14:18
Well appreciated Gilles.
â needtoknow
Mar 25 at 14:18
Well appreciated Gilles.
â needtoknow
Mar 25 at 14:18
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f433087%2fhow-to-remove-the-trailing-slash-from-a-variable-which-defines-a-directory-from%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password