bash + how to increment variables that contain letters a..z
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
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
add a comment |Â
up vote
0
down vote
favorite
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
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
linux bash shell-script rhel
asked Oct 2 '17 at 17:01
yael
2,0361145
2,0361145
add a comment |Â
add a comment |Â
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')"
why trailinga
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" toa
.
â DopeGhoti
Oct 2 '17 at 18:19
1
In POSIX complianttr
implementations, that would convertz
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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')"
why trailinga
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" toa
.
â DopeGhoti
Oct 2 '17 at 18:19
1
In POSIX complianttr
implementations, that would convertz
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
add a comment |Â
up vote
5
down vote
accepted
The simple way:
echo "$x,$var"
var="$(echo $var | tr '[a-y]z' '[b-z]a')"
why trailinga
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" toa
.
â DopeGhoti
Oct 2 '17 at 18:19
1
In POSIX complianttr
implementations, that would convertz
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
add a comment |Â
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')"
The simple way:
echo "$x,$var"
var="$(echo $var | tr '[a-y]z' '[b-z]a')"
edited Oct 2 '17 at 20:48
answered Oct 2 '17 at 17:06
DopeGhoti
41k55080
41k55080
why trailinga
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" toa
.
â DopeGhoti
Oct 2 '17 at 18:19
1
In POSIX complianttr
implementations, that would convertz
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
add a comment |Â
why trailinga
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" toa
.
â DopeGhoti
Oct 2 '17 at 18:19
1
In POSIX complianttr
implementations, that would convertz
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
You have an array; just index it:
var=( b..z )
for ((x=0; x<5; x++)); do
echo "$x, $var[x+1]"
done
answered Oct 3 '17 at 1:31
chepner
5,1801223
5,1801223
add a comment |Â
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered Oct 2 '17 at 21:50
drl
45225
45225
add a comment |Â
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%2f395692%2fbash-how-to-increment-variables-that-contain-letters-a-z%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