touch in for loop












2














ls gives me:



10 11 12 12L 13 16 702 702L


etc., and I'd like to create files



10_ 11_ 12_ 12L_ 13_


and so on. But,



$ for f in *; do touch "$f_"; done


gives me:



touch: cannot touch '': No such file or directory
touch: cannot touch '': No such file or directory
touch: cannot touch '': No such file or directory
touch: cannot touch '': No such file or directory


Also,



$ for f in *; do touch $f_; done


gives:



Try 'touch --help' for more information.
touch: missing file operand
Try 'touch --help' for more information.
touch: missing file operand
Try 'touch --help' for more information.
touch: missing file operand


I have over 100 files in this directory and haven't intention to do this without script.










share|improve this question





























    2














    ls gives me:



    10 11 12 12L 13 16 702 702L


    etc., and I'd like to create files



    10_ 11_ 12_ 12L_ 13_


    and so on. But,



    $ for f in *; do touch "$f_"; done


    gives me:



    touch: cannot touch '': No such file or directory
    touch: cannot touch '': No such file or directory
    touch: cannot touch '': No such file or directory
    touch: cannot touch '': No such file or directory


    Also,



    $ for f in *; do touch $f_; done


    gives:



    Try 'touch --help' for more information.
    touch: missing file operand
    Try 'touch --help' for more information.
    touch: missing file operand
    Try 'touch --help' for more information.
    touch: missing file operand


    I have over 100 files in this directory and haven't intention to do this without script.










    share|improve this question



























      2












      2








      2







      ls gives me:



      10 11 12 12L 13 16 702 702L


      etc., and I'd like to create files



      10_ 11_ 12_ 12L_ 13_


      and so on. But,



      $ for f in *; do touch "$f_"; done


      gives me:



      touch: cannot touch '': No such file or directory
      touch: cannot touch '': No such file or directory
      touch: cannot touch '': No such file or directory
      touch: cannot touch '': No such file or directory


      Also,



      $ for f in *; do touch $f_; done


      gives:



      Try 'touch --help' for more information.
      touch: missing file operand
      Try 'touch --help' for more information.
      touch: missing file operand
      Try 'touch --help' for more information.
      touch: missing file operand


      I have over 100 files in this directory and haven't intention to do this without script.










      share|improve this question















      ls gives me:



      10 11 12 12L 13 16 702 702L


      etc., and I'd like to create files



      10_ 11_ 12_ 12L_ 13_


      and so on. But,



      $ for f in *; do touch "$f_"; done


      gives me:



      touch: cannot touch '': No such file or directory
      touch: cannot touch '': No such file or directory
      touch: cannot touch '': No such file or directory
      touch: cannot touch '': No such file or directory


      Also,



      $ for f in *; do touch $f_; done


      gives:



      Try 'touch --help' for more information.
      touch: missing file operand
      Try 'touch --help' for more information.
      touch: missing file operand
      Try 'touch --help' for more information.
      touch: missing file operand


      I have over 100 files in this directory and haven't intention to do this without script.







      bash






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 18 '18 at 0:45









      Stefan Hamcke

      3951522




      3951522










      asked Dec 17 '18 at 22:31









      mk1024

      177314




      177314






















          1 Answer
          1






          active

          oldest

          votes


















          7














          You could do it this way:



          for f in *; do touch "${f}_"; done


          man bash/EXPANSION says:




          The braces are required when parameter is a positional parameter with
          more than one digit, or when parameter is followed by a character
          which is not to be interpreted as part of its name
          .




          However, this calls touch for every single file, which is quite inefficient. A better way is to let printf make a list of the files, zero-delimited in case of weird file names, and call touch only as often as needed with the help of xargs:



          printf '%s_' * | xargs -0 touch





          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            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',
            autoActivateHeartbeat: false,
            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%2faskubuntu.com%2fquestions%2f1102663%2ftouch-in-for-loop%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            7














            You could do it this way:



            for f in *; do touch "${f}_"; done


            man bash/EXPANSION says:




            The braces are required when parameter is a positional parameter with
            more than one digit, or when parameter is followed by a character
            which is not to be interpreted as part of its name
            .




            However, this calls touch for every single file, which is quite inefficient. A better way is to let printf make a list of the files, zero-delimited in case of weird file names, and call touch only as often as needed with the help of xargs:



            printf '%s_' * | xargs -0 touch





            share|improve this answer




























              7














              You could do it this way:



              for f in *; do touch "${f}_"; done


              man bash/EXPANSION says:




              The braces are required when parameter is a positional parameter with
              more than one digit, or when parameter is followed by a character
              which is not to be interpreted as part of its name
              .




              However, this calls touch for every single file, which is quite inefficient. A better way is to let printf make a list of the files, zero-delimited in case of weird file names, and call touch only as often as needed with the help of xargs:



              printf '%s_' * | xargs -0 touch





              share|improve this answer


























                7












                7








                7






                You could do it this way:



                for f in *; do touch "${f}_"; done


                man bash/EXPANSION says:




                The braces are required when parameter is a positional parameter with
                more than one digit, or when parameter is followed by a character
                which is not to be interpreted as part of its name
                .




                However, this calls touch for every single file, which is quite inefficient. A better way is to let printf make a list of the files, zero-delimited in case of weird file names, and call touch only as often as needed with the help of xargs:



                printf '%s_' * | xargs -0 touch





                share|improve this answer














                You could do it this way:



                for f in *; do touch "${f}_"; done


                man bash/EXPANSION says:




                The braces are required when parameter is a positional parameter with
                more than one digit, or when parameter is followed by a character
                which is not to be interpreted as part of its name
                .




                However, this calls touch for every single file, which is quite inefficient. A better way is to let printf make a list of the files, zero-delimited in case of weird file names, and call touch only as often as needed with the help of xargs:



                printf '%s_' * | xargs -0 touch






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 17 '18 at 23:15

























                answered Dec 17 '18 at 22:43









                dessert

                22k56198




                22k56198






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1102663%2ftouch-in-for-loop%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á

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