bash + how to increment variables that contain letters a..z

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite
1












how to increment variables - $var that contain the letters a..z



example:



 var=(b..z)
for x in 1 2 3 4 5
do
echo $x,$var

$var++ ( this is wrong but I need to do something like this )

done


expected output:



 1,b
2,c
3,d
4,e
5,f
.
.
.









share|improve this question

























    up vote
    0
    down vote

    favorite
    1












    how to increment variables - $var that contain the letters a..z



    example:



     var=(b..z)
    for x in 1 2 3 4 5
    do
    echo $x,$var

    $var++ ( this is wrong but I need to do something like this )

    done


    expected output:



     1,b
    2,c
    3,d
    4,e
    5,f
    .
    .
    .









    share|improve this question























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      how to increment variables - $var that contain the letters a..z



      example:



       var=(b..z)
      for x in 1 2 3 4 5
      do
      echo $x,$var

      $var++ ( this is wrong but I need to do something like this )

      done


      expected output:



       1,b
      2,c
      3,d
      4,e
      5,f
      .
      .
      .









      share|improve this question













      how to increment variables - $var that contain the letters a..z



      example:



       var=(b..z)
      for x in 1 2 3 4 5
      do
      echo $x,$var

      $var++ ( this is wrong but I need to do something like this )

      done


      expected output:



       1,b
      2,c
      3,d
      4,e
      5,f
      .
      .
      .






      linux bash shell-script rhel






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 2 '17 at 17:01









      yael

      2,0361145




      2,0361145




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          5
          down vote



          accepted










          The simple way:



          echo "$x,$var"
          var="$(echo $var | tr '[a-y]z' '[b-z]a')"





          share|improve this answer






















          • why trailing a in [...]a ?
            – RomanPerekhrest
            Oct 2 '17 at 17:36







          • 2




            Absent direction for what an "incremented" z would become, I opted to have it "wrap around" to a.
            – DopeGhoti
            Oct 2 '17 at 18:19






          • 1




            In POSIX compliant tr implementations, that would convert z to ]. POSIXly: tr a-z b-za. To be compatible with both POSIX and SysV: tr '[a-y]z' '[b-z]a'
            – Stéphane Chazelas
            Oct 2 '17 at 19:43

















          up vote
          2
          down vote













          You have an array; just index it:



          var=( b..z )
          for ((x=0; x<5; x++)); do
          echo "$x, $var[x+1]"
          done





          share|improve this answer



























            up vote
            1
            down vote













            paste -d, <( printf "%sn" 1..25 ) <( printf "%sn" b..z )


            producing:



            1,b
            2,c
            3,d
            4,e
            5,f
            6,g
            .
            .


            For a system like:



            OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
            Distribution : Debian 8.9 (jessie)
            bash GNU bash 4.3.30
            paste (GNU coreutils) 8.23





            share|improve this answer




















              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%2f395692%2fbash-how-to-increment-variables-that-contain-letters-a-z%23new-answer', 'question_page');

              );

              Post as a guest






























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              5
              down vote



              accepted










              The simple way:



              echo "$x,$var"
              var="$(echo $var | tr '[a-y]z' '[b-z]a')"





              share|improve this answer






















              • why trailing a in [...]a ?
                – RomanPerekhrest
                Oct 2 '17 at 17:36







              • 2




                Absent direction for what an "incremented" z would become, I opted to have it "wrap around" to a.
                – DopeGhoti
                Oct 2 '17 at 18:19






              • 1




                In POSIX compliant tr implementations, that would convert z to ]. POSIXly: tr a-z b-za. To be compatible with both POSIX and SysV: tr '[a-y]z' '[b-z]a'
                – Stéphane Chazelas
                Oct 2 '17 at 19:43














              up vote
              5
              down vote



              accepted










              The simple way:



              echo "$x,$var"
              var="$(echo $var | tr '[a-y]z' '[b-z]a')"





              share|improve this answer






















              • why trailing a in [...]a ?
                – RomanPerekhrest
                Oct 2 '17 at 17:36







              • 2




                Absent direction for what an "incremented" z would become, I opted to have it "wrap around" to a.
                – DopeGhoti
                Oct 2 '17 at 18:19






              • 1




                In POSIX compliant tr implementations, that would convert z to ]. POSIXly: tr a-z b-za. To be compatible with both POSIX and SysV: tr '[a-y]z' '[b-z]a'
                – Stéphane Chazelas
                Oct 2 '17 at 19:43












              up vote
              5
              down vote



              accepted







              up vote
              5
              down vote



              accepted






              The simple way:



              echo "$x,$var"
              var="$(echo $var | tr '[a-y]z' '[b-z]a')"





              share|improve this answer














              The simple way:



              echo "$x,$var"
              var="$(echo $var | tr '[a-y]z' '[b-z]a')"






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Oct 2 '17 at 20:48

























              answered Oct 2 '17 at 17:06









              DopeGhoti

              41k55080




              41k55080











              • why trailing a in [...]a ?
                – RomanPerekhrest
                Oct 2 '17 at 17:36







              • 2




                Absent direction for what an "incremented" z would become, I opted to have it "wrap around" to a.
                – DopeGhoti
                Oct 2 '17 at 18:19






              • 1




                In POSIX compliant tr implementations, that would convert z to ]. POSIXly: tr a-z b-za. To be compatible with both POSIX and SysV: tr '[a-y]z' '[b-z]a'
                – Stéphane Chazelas
                Oct 2 '17 at 19:43
















              • why trailing a in [...]a ?
                – RomanPerekhrest
                Oct 2 '17 at 17:36







              • 2




                Absent direction for what an "incremented" z would become, I opted to have it "wrap around" to a.
                – DopeGhoti
                Oct 2 '17 at 18:19






              • 1




                In POSIX compliant tr implementations, that would convert z to ]. POSIXly: tr a-z b-za. To be compatible with both POSIX and SysV: tr '[a-y]z' '[b-z]a'
                – Stéphane Chazelas
                Oct 2 '17 at 19:43















              why trailing a in [...]a ?
              – RomanPerekhrest
              Oct 2 '17 at 17:36





              why trailing a in [...]a ?
              – RomanPerekhrest
              Oct 2 '17 at 17:36





              2




              2




              Absent direction for what an "incremented" z would become, I opted to have it "wrap around" to a.
              – DopeGhoti
              Oct 2 '17 at 18:19




              Absent direction for what an "incremented" z would become, I opted to have it "wrap around" to a.
              – DopeGhoti
              Oct 2 '17 at 18:19




              1




              1




              In POSIX compliant tr implementations, that would convert z to ]. POSIXly: tr a-z b-za. To be compatible with both POSIX and SysV: tr '[a-y]z' '[b-z]a'
              – Stéphane Chazelas
              Oct 2 '17 at 19:43




              In POSIX compliant tr implementations, that would convert z to ]. POSIXly: tr a-z b-za. To be compatible with both POSIX and SysV: tr '[a-y]z' '[b-z]a'
              – Stéphane Chazelas
              Oct 2 '17 at 19:43












              up vote
              2
              down vote













              You have an array; just index it:



              var=( b..z )
              for ((x=0; x<5; x++)); do
              echo "$x, $var[x+1]"
              done





              share|improve this answer
























                up vote
                2
                down vote













                You have an array; just index it:



                var=( b..z )
                for ((x=0; x<5; x++)); do
                echo "$x, $var[x+1]"
                done





                share|improve this answer






















                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  You have an array; just index it:



                  var=( b..z )
                  for ((x=0; x<5; x++)); do
                  echo "$x, $var[x+1]"
                  done





                  share|improve this answer












                  You have an array; just index it:



                  var=( b..z )
                  for ((x=0; x<5; x++)); do
                  echo "$x, $var[x+1]"
                  done






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 3 '17 at 1:31









                  chepner

                  5,1801223




                  5,1801223




















                      up vote
                      1
                      down vote













                      paste -d, <( printf "%sn" 1..25 ) <( printf "%sn" b..z )


                      producing:



                      1,b
                      2,c
                      3,d
                      4,e
                      5,f
                      6,g
                      .
                      .


                      For a system like:



                      OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
                      Distribution : Debian 8.9 (jessie)
                      bash GNU bash 4.3.30
                      paste (GNU coreutils) 8.23





                      share|improve this answer
























                        up vote
                        1
                        down vote













                        paste -d, <( printf "%sn" 1..25 ) <( printf "%sn" b..z )


                        producing:



                        1,b
                        2,c
                        3,d
                        4,e
                        5,f
                        6,g
                        .
                        .


                        For a system like:



                        OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
                        Distribution : Debian 8.9 (jessie)
                        bash GNU bash 4.3.30
                        paste (GNU coreutils) 8.23





                        share|improve this answer






















                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          paste -d, <( printf "%sn" 1..25 ) <( printf "%sn" b..z )


                          producing:



                          1,b
                          2,c
                          3,d
                          4,e
                          5,f
                          6,g
                          .
                          .


                          For a system like:



                          OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
                          Distribution : Debian 8.9 (jessie)
                          bash GNU bash 4.3.30
                          paste (GNU coreutils) 8.23





                          share|improve this answer












                          paste -d, <( printf "%sn" 1..25 ) <( printf "%sn" b..z )


                          producing:



                          1,b
                          2,c
                          3,d
                          4,e
                          5,f
                          6,g
                          .
                          .


                          For a system like:



                          OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
                          Distribution : Debian 8.9 (jessie)
                          bash GNU bash 4.3.30
                          paste (GNU coreutils) 8.23






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Oct 2 '17 at 21:50









                          drl

                          45225




                          45225



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f395692%2fbash-how-to-increment-variables-that-contain-letters-a-z%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