How to remove the trailing slash from a variable which defines a directory from a time test output

The name of the pictureThe name of the pictureThe name of the pictureClash 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 ...






share|improve this question


























    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 ...






    share|improve this question
























      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 ...






      share|improve this question














      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 ...








      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 14:52

























      asked Mar 23 at 14:50









      needtoknow

      1286




      1286




















          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.







          share|improve this answer






















          • Well appreciated Gilles.
            – needtoknow
            Mar 25 at 14:18










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          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






























          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.







          share|improve this answer






















          • Well appreciated Gilles.
            – needtoknow
            Mar 25 at 14:18














          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.







          share|improve this answer






















          • Well appreciated Gilles.
            – needtoknow
            Mar 25 at 14:18












          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.







          share|improve this answer














          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.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          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
















          • 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












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay