Groovy syntax not working with backslashes











up vote
0
down vote

favorite












I'm trying to use a backslash on the command bellow at groovy syntax:



find /path/folder-* -type f -iname "file*" -exec rm -f {} ;


When I try to build this command on a Jenkins pipeline give me an error about this syntax. Even before I do this command have a warning with red syntax on Jenkins form field saying unexpected char: ''.



What could I do for replace or fix error with this backslash ?



Groovy commands:



node ("instance") {
stage ("cleaning folders"){
sh '''
find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} ;
'''
}
stage ("instance1"){
sh '''
rm -f /root/logfiles/instance1/*
echo instance1;
scp 100.0.0.50:/var/log/file1.log /root/logfiles/instance1/file1.log;
scp 100.0.0.50:/var/log/file2.log /root/logfiles/instance1/file2.log;
'''
}
stage ("instance1"){
sh '''
rm -f /root/logfiles/instance2/*
echo instance2;
scp 100.0.0.51:/var/log/file1.log /root/logfiles/instance2/file1.log;
scp 100.0.0.51:/var/log/file2.log /root/logfiles/instance2/file2.log;
'''
}
}


Notice: I have rm -f for all instances at this moment. Will substitute all rm -f to the find command on the stage cleaning folders.



Tks in advance










share|improve this question
























  • this hybrid slash wont help you? ` ∖ `
    – user902300
    May 26 at 13:43






  • 1




    Could you please post your Groovy script (or Pipeline, or whatever it is that you're using to run that command)?
    – jayhendren
    May 29 at 15:57










  • Pasted on question body the groovy script. @jayhendren
    – Marlon
    May 30 at 9:27










  • Since the slash character is simply escaping the following one, it may be that you just need to remove ir.
    – davidgo
    May 30 at 9:35






  • 1




    @davidgo in this particular case the backslash is definitely necessary to ensure the semicolon is parsed by find and not the shell.
    – jayhendren
    May 30 at 17:19















up vote
0
down vote

favorite












I'm trying to use a backslash on the command bellow at groovy syntax:



find /path/folder-* -type f -iname "file*" -exec rm -f {} ;


When I try to build this command on a Jenkins pipeline give me an error about this syntax. Even before I do this command have a warning with red syntax on Jenkins form field saying unexpected char: ''.



What could I do for replace or fix error with this backslash ?



Groovy commands:



node ("instance") {
stage ("cleaning folders"){
sh '''
find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} ;
'''
}
stage ("instance1"){
sh '''
rm -f /root/logfiles/instance1/*
echo instance1;
scp 100.0.0.50:/var/log/file1.log /root/logfiles/instance1/file1.log;
scp 100.0.0.50:/var/log/file2.log /root/logfiles/instance1/file2.log;
'''
}
stage ("instance1"){
sh '''
rm -f /root/logfiles/instance2/*
echo instance2;
scp 100.0.0.51:/var/log/file1.log /root/logfiles/instance2/file1.log;
scp 100.0.0.51:/var/log/file2.log /root/logfiles/instance2/file2.log;
'''
}
}


Notice: I have rm -f for all instances at this moment. Will substitute all rm -f to the find command on the stage cleaning folders.



Tks in advance










share|improve this question
























  • this hybrid slash wont help you? ` ∖ `
    – user902300
    May 26 at 13:43






  • 1




    Could you please post your Groovy script (or Pipeline, or whatever it is that you're using to run that command)?
    – jayhendren
    May 29 at 15:57










  • Pasted on question body the groovy script. @jayhendren
    – Marlon
    May 30 at 9:27










  • Since the slash character is simply escaping the following one, it may be that you just need to remove ir.
    – davidgo
    May 30 at 9:35






  • 1




    @davidgo in this particular case the backslash is definitely necessary to ensure the semicolon is parsed by find and not the shell.
    – jayhendren
    May 30 at 17:19













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to use a backslash on the command bellow at groovy syntax:



find /path/folder-* -type f -iname "file*" -exec rm -f {} ;


When I try to build this command on a Jenkins pipeline give me an error about this syntax. Even before I do this command have a warning with red syntax on Jenkins form field saying unexpected char: ''.



What could I do for replace or fix error with this backslash ?



Groovy commands:



node ("instance") {
stage ("cleaning folders"){
sh '''
find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} ;
'''
}
stage ("instance1"){
sh '''
rm -f /root/logfiles/instance1/*
echo instance1;
scp 100.0.0.50:/var/log/file1.log /root/logfiles/instance1/file1.log;
scp 100.0.0.50:/var/log/file2.log /root/logfiles/instance1/file2.log;
'''
}
stage ("instance1"){
sh '''
rm -f /root/logfiles/instance2/*
echo instance2;
scp 100.0.0.51:/var/log/file1.log /root/logfiles/instance2/file1.log;
scp 100.0.0.51:/var/log/file2.log /root/logfiles/instance2/file2.log;
'''
}
}


Notice: I have rm -f for all instances at this moment. Will substitute all rm -f to the find command on the stage cleaning folders.



Tks in advance










share|improve this question















I'm trying to use a backslash on the command bellow at groovy syntax:



find /path/folder-* -type f -iname "file*" -exec rm -f {} ;


When I try to build this command on a Jenkins pipeline give me an error about this syntax. Even before I do this command have a warning with red syntax on Jenkins form field saying unexpected char: ''.



What could I do for replace or fix error with this backslash ?



Groovy commands:



node ("instance") {
stage ("cleaning folders"){
sh '''
find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} ;
'''
}
stage ("instance1"){
sh '''
rm -f /root/logfiles/instance1/*
echo instance1;
scp 100.0.0.50:/var/log/file1.log /root/logfiles/instance1/file1.log;
scp 100.0.0.50:/var/log/file2.log /root/logfiles/instance1/file2.log;
'''
}
stage ("instance1"){
sh '''
rm -f /root/logfiles/instance2/*
echo instance2;
scp 100.0.0.51:/var/log/file1.log /root/logfiles/instance2/file1.log;
scp 100.0.0.51:/var/log/file2.log /root/logfiles/instance2/file2.log;
'''
}
}


Notice: I have rm -f for all instances at this moment. Will substitute all rm -f to the find command on the stage cleaning folders.



Tks in advance







bash find bash-scripting jenkins groovy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 30 at 9:36









davidgo

41.4k74985




41.4k74985










asked May 26 at 8:02









Marlon

51211




51211












  • this hybrid slash wont help you? ` ∖ `
    – user902300
    May 26 at 13:43






  • 1




    Could you please post your Groovy script (or Pipeline, or whatever it is that you're using to run that command)?
    – jayhendren
    May 29 at 15:57










  • Pasted on question body the groovy script. @jayhendren
    – Marlon
    May 30 at 9:27










  • Since the slash character is simply escaping the following one, it may be that you just need to remove ir.
    – davidgo
    May 30 at 9:35






  • 1




    @davidgo in this particular case the backslash is definitely necessary to ensure the semicolon is parsed by find and not the shell.
    – jayhendren
    May 30 at 17:19


















  • this hybrid slash wont help you? ` ∖ `
    – user902300
    May 26 at 13:43






  • 1




    Could you please post your Groovy script (or Pipeline, or whatever it is that you're using to run that command)?
    – jayhendren
    May 29 at 15:57










  • Pasted on question body the groovy script. @jayhendren
    – Marlon
    May 30 at 9:27










  • Since the slash character is simply escaping the following one, it may be that you just need to remove ir.
    – davidgo
    May 30 at 9:35






  • 1




    @davidgo in this particular case the backslash is definitely necessary to ensure the semicolon is parsed by find and not the shell.
    – jayhendren
    May 30 at 17:19
















this hybrid slash wont help you? ` ∖ `
– user902300
May 26 at 13:43




this hybrid slash wont help you? ` ∖ `
– user902300
May 26 at 13:43




1




1




Could you please post your Groovy script (or Pipeline, or whatever it is that you're using to run that command)?
– jayhendren
May 29 at 15:57




Could you please post your Groovy script (or Pipeline, or whatever it is that you're using to run that command)?
– jayhendren
May 29 at 15:57












Pasted on question body the groovy script. @jayhendren
– Marlon
May 30 at 9:27




Pasted on question body the groovy script. @jayhendren
– Marlon
May 30 at 9:27












Since the slash character is simply escaping the following one, it may be that you just need to remove ir.
– davidgo
May 30 at 9:35




Since the slash character is simply escaping the following one, it may be that you just need to remove ir.
– davidgo
May 30 at 9:35




1




1




@davidgo in this particular case the backslash is definitely necessary to ensure the semicolon is parsed by find and not the shell.
– jayhendren
May 30 at 17:19




@davidgo in this particular case the backslash is definitely necessary to ensure the semicolon is parsed by find and not the shell.
– jayhendren
May 30 at 17:19










3 Answers
3






active

oldest

votes

















up vote
3
down vote



accepted










It might help to escape your escape character, as funny as this might sound. Just put another backslash in front of your backslash:



stage ("cleaning folders"){
sh '''
find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} \;
'''
}


At least IntelliJ does not mark this as syntactically wrong.






share|improve this answer





















  • It sound that worked fine. Tks!
    – Marlon
    Jun 7 at 3:57


















up vote
0
down vote













Actually in your case I would not even bother to figure out proper escaping:



stage ("cleaning folders"){
sh '''
find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} +
'''
}


When you pass a semicolon to -exec, find constructs multiple commands, one for each result of the find operation (e.g. rm -f /root/logfiles/instance/file1.log, rm -f /root/logfiles/instance/file2.log, ...), but when you use a plus, find constructs a single command with multiple arguments, which is much more efficient and fast (e.g. rm -f /root/logfiles/instance/file1.log /root/logfiles/instance/file2.log ...). See the man page for find for more detail (sorry I can't quote the man page or provide more detail right now; I'm on mobile).






share|improve this answer




























    up vote
    0
    down vote













    One solution would be to use dollar slashy which disables string interpolation and changes escape char to $.



    stage ("cleaning folders"){
    sh script: $/
    find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} ;
    /$
    }





    share|improve this answer








    New contributor




    jikuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.


















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      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: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1326117%2fgroovy-syntax-not-working-with-backslashes%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      3
      down vote



      accepted










      It might help to escape your escape character, as funny as this might sound. Just put another backslash in front of your backslash:



      stage ("cleaning folders"){
      sh '''
      find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} \;
      '''
      }


      At least IntelliJ does not mark this as syntactically wrong.






      share|improve this answer





















      • It sound that worked fine. Tks!
        – Marlon
        Jun 7 at 3:57















      up vote
      3
      down vote



      accepted










      It might help to escape your escape character, as funny as this might sound. Just put another backslash in front of your backslash:



      stage ("cleaning folders"){
      sh '''
      find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} \;
      '''
      }


      At least IntelliJ does not mark this as syntactically wrong.






      share|improve this answer





















      • It sound that worked fine. Tks!
        – Marlon
        Jun 7 at 3:57













      up vote
      3
      down vote



      accepted







      up vote
      3
      down vote



      accepted






      It might help to escape your escape character, as funny as this might sound. Just put another backslash in front of your backslash:



      stage ("cleaning folders"){
      sh '''
      find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} \;
      '''
      }


      At least IntelliJ does not mark this as syntactically wrong.






      share|improve this answer












      It might help to escape your escape character, as funny as this might sound. Just put another backslash in front of your backslash:



      stage ("cleaning folders"){
      sh '''
      find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} \;
      '''
      }


      At least IntelliJ does not mark this as syntactically wrong.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered May 30 at 9:49









      Aarkon

      463




      463












      • It sound that worked fine. Tks!
        – Marlon
        Jun 7 at 3:57


















      • It sound that worked fine. Tks!
        – Marlon
        Jun 7 at 3:57
















      It sound that worked fine. Tks!
      – Marlon
      Jun 7 at 3:57




      It sound that worked fine. Tks!
      – Marlon
      Jun 7 at 3:57












      up vote
      0
      down vote













      Actually in your case I would not even bother to figure out proper escaping:



      stage ("cleaning folders"){
      sh '''
      find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} +
      '''
      }


      When you pass a semicolon to -exec, find constructs multiple commands, one for each result of the find operation (e.g. rm -f /root/logfiles/instance/file1.log, rm -f /root/logfiles/instance/file2.log, ...), but when you use a plus, find constructs a single command with multiple arguments, which is much more efficient and fast (e.g. rm -f /root/logfiles/instance/file1.log /root/logfiles/instance/file2.log ...). See the man page for find for more detail (sorry I can't quote the man page or provide more detail right now; I'm on mobile).






      share|improve this answer

























        up vote
        0
        down vote













        Actually in your case I would not even bother to figure out proper escaping:



        stage ("cleaning folders"){
        sh '''
        find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} +
        '''
        }


        When you pass a semicolon to -exec, find constructs multiple commands, one for each result of the find operation (e.g. rm -f /root/logfiles/instance/file1.log, rm -f /root/logfiles/instance/file2.log, ...), but when you use a plus, find constructs a single command with multiple arguments, which is much more efficient and fast (e.g. rm -f /root/logfiles/instance/file1.log /root/logfiles/instance/file2.log ...). See the man page for find for more detail (sorry I can't quote the man page or provide more detail right now; I'm on mobile).






        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote









          Actually in your case I would not even bother to figure out proper escaping:



          stage ("cleaning folders"){
          sh '''
          find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} +
          '''
          }


          When you pass a semicolon to -exec, find constructs multiple commands, one for each result of the find operation (e.g. rm -f /root/logfiles/instance/file1.log, rm -f /root/logfiles/instance/file2.log, ...), but when you use a plus, find constructs a single command with multiple arguments, which is much more efficient and fast (e.g. rm -f /root/logfiles/instance/file1.log /root/logfiles/instance/file2.log ...). See the man page for find for more detail (sorry I can't quote the man page or provide more detail right now; I'm on mobile).






          share|improve this answer












          Actually in your case I would not even bother to figure out proper escaping:



          stage ("cleaning folders"){
          sh '''
          find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} +
          '''
          }


          When you pass a semicolon to -exec, find constructs multiple commands, one for each result of the find operation (e.g. rm -f /root/logfiles/instance/file1.log, rm -f /root/logfiles/instance/file2.log, ...), but when you use a plus, find constructs a single command with multiple arguments, which is much more efficient and fast (e.g. rm -f /root/logfiles/instance/file1.log /root/logfiles/instance/file2.log ...). See the man page for find for more detail (sorry I can't quote the man page or provide more detail right now; I'm on mobile).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 30 at 17:29









          jayhendren

          228210




          228210






















              up vote
              0
              down vote













              One solution would be to use dollar slashy which disables string interpolation and changes escape char to $.



              stage ("cleaning folders"){
              sh script: $/
              find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} ;
              /$
              }





              share|improve this answer








              New contributor




              jikuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






















                up vote
                0
                down vote













                One solution would be to use dollar slashy which disables string interpolation and changes escape char to $.



                stage ("cleaning folders"){
                sh script: $/
                find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} ;
                /$
                }





                share|improve this answer








                New contributor




                jikuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.




















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  One solution would be to use dollar slashy which disables string interpolation and changes escape char to $.



                  stage ("cleaning folders"){
                  sh script: $/
                  find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} ;
                  /$
                  }





                  share|improve this answer








                  New contributor




                  jikuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  One solution would be to use dollar slashy which disables string interpolation and changes escape char to $.



                  stage ("cleaning folders"){
                  sh script: $/
                  find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} ;
                  /$
                  }






                  share|improve this answer








                  New contributor




                  jikuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  jikuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered Nov 21 at 10:43









                  jikuja

                  11




                  11




                  New contributor




                  jikuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  jikuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  jikuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1326117%2fgroovy-syntax-not-working-with-backslashes%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                      Mangá

                       ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕