bash string increase from vda to vdb in a loop
I would like to increase a string by one, for example, from vda
to vdb
, from vdb
to vdc
and so on.
I was able to do it in one of the languages in the past by doing something like:
$c="vdb"+1
and
c == vdc
after that.
currently, I have a line which gets the last vd*
disk from a VM:
current=$(virsh domblklist cic-1_vm | grep vd | awk '{print $1}' | sort -n | tail -n 1)
I want it to be added to virsh disk-attach
command automatically as a target option, like this one:
virsh disk-attach $VM $DISK_FILE $DISK_NAME
SO I could do $DISK_NAME
from $current
automatically, without predefined case or smth...
bash string
add a comment |
I would like to increase a string by one, for example, from vda
to vdb
, from vdb
to vdc
and so on.
I was able to do it in one of the languages in the past by doing something like:
$c="vdb"+1
and
c == vdc
after that.
currently, I have a line which gets the last vd*
disk from a VM:
current=$(virsh domblklist cic-1_vm | grep vd | awk '{print $1}' | sort -n | tail -n 1)
I want it to be added to virsh disk-attach
command automatically as a target option, like this one:
virsh disk-attach $VM $DISK_FILE $DISK_NAME
SO I could do $DISK_NAME
from $current
automatically, without predefined case or smth...
bash string
add a comment |
I would like to increase a string by one, for example, from vda
to vdb
, from vdb
to vdc
and so on.
I was able to do it in one of the languages in the past by doing something like:
$c="vdb"+1
and
c == vdc
after that.
currently, I have a line which gets the last vd*
disk from a VM:
current=$(virsh domblklist cic-1_vm | grep vd | awk '{print $1}' | sort -n | tail -n 1)
I want it to be added to virsh disk-attach
command automatically as a target option, like this one:
virsh disk-attach $VM $DISK_FILE $DISK_NAME
SO I could do $DISK_NAME
from $current
automatically, without predefined case or smth...
bash string
I would like to increase a string by one, for example, from vda
to vdb
, from vdb
to vdc
and so on.
I was able to do it in one of the languages in the past by doing something like:
$c="vdb"+1
and
c == vdc
after that.
currently, I have a line which gets the last vd*
disk from a VM:
current=$(virsh domblklist cic-1_vm | grep vd | awk '{print $1}' | sort -n | tail -n 1)
I want it to be added to virsh disk-attach
command automatically as a target option, like this one:
virsh disk-attach $VM $DISK_FILE $DISK_NAME
SO I could do $DISK_NAME
from $current
automatically, without predefined case or smth...
bash string
bash string
edited Dec 12 at 16:22
SouravGhosh
409310
409310
asked Dec 12 at 10:05
BiG_NoBoDy
288
288
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
letter=${current#??}
letter=$( tr 'a-y' 'b-z' <<<"$letter" )
next="${current%?}$letter"
This first extracts the last letter of $current
by deleting the first two characters. It then uses tr
to shift the letter to the next one in the alphabet.
At the end, next
is assigned the first two characters of $current
(the last one removed) and concatenates that with the shifted letter.
If $current
is vdc
, $next
will be vdd
.
I understand, but it will stop at when hits the last one... I do not know what the last will be:current=$(virsh domblklist cic-1_vm | grep vd | awk '{print $1}' | sort -n | tail -n 1)
so I want to add to this a "next" disk
– BiG_NoBoDy
Dec 12 at 10:11
@BiG_NoBoDy See update. You question does not show that you know how manyvd
strings that you want to create, or what these string are, or any other background or context.
– Kusalananda
Dec 12 at 10:13
Ok, I'll update it in propper way.
– BiG_NoBoDy
Dec 12 at 10:14
@BiG_NoBoDy Thanks! See updated answer.
– Kusalananda
Dec 12 at 10:34
Kusalananda > thank you
– BiG_NoBoDy
Dec 12 at 15:16
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487539%2fbash-string-increase-from-vda-to-vdb-in-a-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
letter=${current#??}
letter=$( tr 'a-y' 'b-z' <<<"$letter" )
next="${current%?}$letter"
This first extracts the last letter of $current
by deleting the first two characters. It then uses tr
to shift the letter to the next one in the alphabet.
At the end, next
is assigned the first two characters of $current
(the last one removed) and concatenates that with the shifted letter.
If $current
is vdc
, $next
will be vdd
.
I understand, but it will stop at when hits the last one... I do not know what the last will be:current=$(virsh domblklist cic-1_vm | grep vd | awk '{print $1}' | sort -n | tail -n 1)
so I want to add to this a "next" disk
– BiG_NoBoDy
Dec 12 at 10:11
@BiG_NoBoDy See update. You question does not show that you know how manyvd
strings that you want to create, or what these string are, or any other background or context.
– Kusalananda
Dec 12 at 10:13
Ok, I'll update it in propper way.
– BiG_NoBoDy
Dec 12 at 10:14
@BiG_NoBoDy Thanks! See updated answer.
– Kusalananda
Dec 12 at 10:34
Kusalananda > thank you
– BiG_NoBoDy
Dec 12 at 15:16
add a comment |
letter=${current#??}
letter=$( tr 'a-y' 'b-z' <<<"$letter" )
next="${current%?}$letter"
This first extracts the last letter of $current
by deleting the first two characters. It then uses tr
to shift the letter to the next one in the alphabet.
At the end, next
is assigned the first two characters of $current
(the last one removed) and concatenates that with the shifted letter.
If $current
is vdc
, $next
will be vdd
.
I understand, but it will stop at when hits the last one... I do not know what the last will be:current=$(virsh domblklist cic-1_vm | grep vd | awk '{print $1}' | sort -n | tail -n 1)
so I want to add to this a "next" disk
– BiG_NoBoDy
Dec 12 at 10:11
@BiG_NoBoDy See update. You question does not show that you know how manyvd
strings that you want to create, or what these string are, or any other background or context.
– Kusalananda
Dec 12 at 10:13
Ok, I'll update it in propper way.
– BiG_NoBoDy
Dec 12 at 10:14
@BiG_NoBoDy Thanks! See updated answer.
– Kusalananda
Dec 12 at 10:34
Kusalananda > thank you
– BiG_NoBoDy
Dec 12 at 15:16
add a comment |
letter=${current#??}
letter=$( tr 'a-y' 'b-z' <<<"$letter" )
next="${current%?}$letter"
This first extracts the last letter of $current
by deleting the first two characters. It then uses tr
to shift the letter to the next one in the alphabet.
At the end, next
is assigned the first two characters of $current
(the last one removed) and concatenates that with the shifted letter.
If $current
is vdc
, $next
will be vdd
.
letter=${current#??}
letter=$( tr 'a-y' 'b-z' <<<"$letter" )
next="${current%?}$letter"
This first extracts the last letter of $current
by deleting the first two characters. It then uses tr
to shift the letter to the next one in the alphabet.
At the end, next
is assigned the first two characters of $current
(the last one removed) and concatenates that with the shifted letter.
If $current
is vdc
, $next
will be vdd
.
edited Dec 12 at 10:33
answered Dec 12 at 10:09
Kusalananda
121k16228372
121k16228372
I understand, but it will stop at when hits the last one... I do not know what the last will be:current=$(virsh domblklist cic-1_vm | grep vd | awk '{print $1}' | sort -n | tail -n 1)
so I want to add to this a "next" disk
– BiG_NoBoDy
Dec 12 at 10:11
@BiG_NoBoDy See update. You question does not show that you know how manyvd
strings that you want to create, or what these string are, or any other background or context.
– Kusalananda
Dec 12 at 10:13
Ok, I'll update it in propper way.
– BiG_NoBoDy
Dec 12 at 10:14
@BiG_NoBoDy Thanks! See updated answer.
– Kusalananda
Dec 12 at 10:34
Kusalananda > thank you
– BiG_NoBoDy
Dec 12 at 15:16
add a comment |
I understand, but it will stop at when hits the last one... I do not know what the last will be:current=$(virsh domblklist cic-1_vm | grep vd | awk '{print $1}' | sort -n | tail -n 1)
so I want to add to this a "next" disk
– BiG_NoBoDy
Dec 12 at 10:11
@BiG_NoBoDy See update. You question does not show that you know how manyvd
strings that you want to create, or what these string are, or any other background or context.
– Kusalananda
Dec 12 at 10:13
Ok, I'll update it in propper way.
– BiG_NoBoDy
Dec 12 at 10:14
@BiG_NoBoDy Thanks! See updated answer.
– Kusalananda
Dec 12 at 10:34
Kusalananda > thank you
– BiG_NoBoDy
Dec 12 at 15:16
I understand, but it will stop at when hits the last one... I do not know what the last will be:
current=$(virsh domblklist cic-1_vm | grep vd | awk '{print $1}' | sort -n | tail -n 1)
so I want to add to this a "next" disk– BiG_NoBoDy
Dec 12 at 10:11
I understand, but it will stop at when hits the last one... I do not know what the last will be:
current=$(virsh domblklist cic-1_vm | grep vd | awk '{print $1}' | sort -n | tail -n 1)
so I want to add to this a "next" disk– BiG_NoBoDy
Dec 12 at 10:11
@BiG_NoBoDy See update. You question does not show that you know how many
vd
strings that you want to create, or what these string are, or any other background or context.– Kusalananda
Dec 12 at 10:13
@BiG_NoBoDy See update. You question does not show that you know how many
vd
strings that you want to create, or what these string are, or any other background or context.– Kusalananda
Dec 12 at 10:13
Ok, I'll update it in propper way.
– BiG_NoBoDy
Dec 12 at 10:14
Ok, I'll update it in propper way.
– BiG_NoBoDy
Dec 12 at 10:14
@BiG_NoBoDy Thanks! See updated answer.
– Kusalananda
Dec 12 at 10:34
@BiG_NoBoDy Thanks! See updated answer.
– Kusalananda
Dec 12 at 10:34
Kusalananda > thank you
– BiG_NoBoDy
Dec 12 at 15:16
Kusalananda > thank you
– BiG_NoBoDy
Dec 12 at 15:16
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487539%2fbash-string-increase-from-vda-to-vdb-in-a-loop%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
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