How do I translate 1-26 to a-z in BASH?Get the source directory of a Bash script from within the script itselfHow to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How do I split a string on a delimiter in Bash?Extract filename and extension in BashHow to concatenate string variables in BashReliable way for a Bash script to get the full path to itselfEcho newline in Bash prints literal nBash script and /bin/bash^M: bad interpreter: No such file or directory
Dissuading my girlfriend from a scam
Why does 8 bit truecolor use only 2 bits for blue?
Is it right to use the ideas of non-winning designers in a design contest?
Why are there no wireless switches?
Does the word voltage exist in academic engineering?
How do draw effects during the discard phase work?
Let A,B,C be sets. If A△B=A△C, does this imply that B=C?
Filling attribute tables with values from the same attribute table
What does "先が気になる" mean?
How do I write a vertically-stacked definition of a sequence?
If every star in the universe except the Sun were destroyed, would we die?
What makes an ending "happy"?
What quests do you need to stop at before you make an enemy of a faction for each faction?
Is there some sort of French saying for "a person's signature move"?
How can I know what hashing algorithm SQL Server used to decrypt the encrypted data when using the function DECRYPTBYPASSPHRASE?
Compiler optimization of bitwise not operation
Should I tip on the Amtrak train?
Sinning and G-d's will, what's wrong with this logic?
Did the Byzantines ever attempt to move their capital to Rome?
Python reimplementation of Lost In Space by Tim Hartnell
Did "Dirty Harry" feel lucky?
I won a car in a poker game. How is that taxed in Canada?
Are fast interviews red flags?
Poor management handling of recent sickness and how to approach my return?
How do I translate 1-26 to a-z in BASH?
Get the source directory of a Bash script from within the script itselfHow to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How do I split a string on a delimiter in Bash?Extract filename and extension in BashHow to concatenate string variables in BashReliable way for a Bash script to get the full path to itselfEcho newline in Bash prints literal nBash script and /bin/bash^M: bad interpreter: No such file or directory
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
This is a part of a comp sci homework question.
I want to translate [1-26] to [A-Z] using a bash script.
#/bin/bash
if [ $1 = -u ] && [ $2 = -s ];then
#statements
echo $3 | tr '[1-26]' '[A-Z]'
fi
don't worry too much about about the if statement, thats part of the question I am working on.
When I run ./file.sh -u -s 2
The output is
B
But when I run ./file -u -s 16
The output is
A6
I want it to output
P
bash
|
show 4 more comments
This is a part of a comp sci homework question.
I want to translate [1-26] to [A-Z] using a bash script.
#/bin/bash
if [ $1 = -u ] && [ $2 = -s ];then
#statements
echo $3 | tr '[1-26]' '[A-Z]'
fi
don't worry too much about about the if statement, thats part of the question I am working on.
When I run ./file.sh -u -s 2
The output is
B
But when I run ./file -u -s 16
The output is
A6
I want it to output
P
bash
What will be the output of./file.sh -u -s 216
?
– oguz ismail
Mar 28 at 6:20
well it was unexpected but it gives me BAC
– Juan Pablo
Mar 28 at 6:21
What is the expected output of it?
– oguz ismail
Mar 28 at 6:26
undefined? 216 is greater than 26 so nothing I guess
– Juan Pablo
Mar 28 at 6:34
1
Not easily (if at all) withtr
.
– choroba
Mar 28 at 7:02
|
show 4 more comments
This is a part of a comp sci homework question.
I want to translate [1-26] to [A-Z] using a bash script.
#/bin/bash
if [ $1 = -u ] && [ $2 = -s ];then
#statements
echo $3 | tr '[1-26]' '[A-Z]'
fi
don't worry too much about about the if statement, thats part of the question I am working on.
When I run ./file.sh -u -s 2
The output is
B
But when I run ./file -u -s 16
The output is
A6
I want it to output
P
bash
This is a part of a comp sci homework question.
I want to translate [1-26] to [A-Z] using a bash script.
#/bin/bash
if [ $1 = -u ] && [ $2 = -s ];then
#statements
echo $3 | tr '[1-26]' '[A-Z]'
fi
don't worry too much about about the if statement, thats part of the question I am working on.
When I run ./file.sh -u -s 2
The output is
B
But when I run ./file -u -s 16
The output is
A6
I want it to output
P
bash
bash
asked Mar 28 at 6:16
Juan PabloJuan Pablo
437 bronze badges
437 bronze badges
What will be the output of./file.sh -u -s 216
?
– oguz ismail
Mar 28 at 6:20
well it was unexpected but it gives me BAC
– Juan Pablo
Mar 28 at 6:21
What is the expected output of it?
– oguz ismail
Mar 28 at 6:26
undefined? 216 is greater than 26 so nothing I guess
– Juan Pablo
Mar 28 at 6:34
1
Not easily (if at all) withtr
.
– choroba
Mar 28 at 7:02
|
show 4 more comments
What will be the output of./file.sh -u -s 216
?
– oguz ismail
Mar 28 at 6:20
well it was unexpected but it gives me BAC
– Juan Pablo
Mar 28 at 6:21
What is the expected output of it?
– oguz ismail
Mar 28 at 6:26
undefined? 216 is greater than 26 so nothing I guess
– Juan Pablo
Mar 28 at 6:34
1
Not easily (if at all) withtr
.
– choroba
Mar 28 at 7:02
What will be the output of
./file.sh -u -s 216
?– oguz ismail
Mar 28 at 6:20
What will be the output of
./file.sh -u -s 216
?– oguz ismail
Mar 28 at 6:20
well it was unexpected but it gives me BAC
– Juan Pablo
Mar 28 at 6:21
well it was unexpected but it gives me BAC
– Juan Pablo
Mar 28 at 6:21
What is the expected output of it?
– oguz ismail
Mar 28 at 6:26
What is the expected output of it?
– oguz ismail
Mar 28 at 6:26
undefined? 216 is greater than 26 so nothing I guess
– Juan Pablo
Mar 28 at 6:34
undefined? 216 is greater than 26 so nothing I guess
– Juan Pablo
Mar 28 at 6:34
1
1
Not easily (if at all) with
tr
.– choroba
Mar 28 at 7:02
Not easily (if at all) with
tr
.– choroba
Mar 28 at 7:02
|
show 4 more comments
1 Answer
1
active
oldest
votes
You can use an array of characters and just specify an index:
chars=("", A..Z)
i=26
echo $chars[i] # Z
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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/4.0/"u003ecc by-sa 4.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%2fstackoverflow.com%2fquestions%2f55391213%2fhow-do-i-translate-1-26-to-a-z-in-bash%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
You can use an array of characters and just specify an index:
chars=("", A..Z)
i=26
echo $chars[i] # Z
add a comment |
You can use an array of characters and just specify an index:
chars=("", A..Z)
i=26
echo $chars[i] # Z
add a comment |
You can use an array of characters and just specify an index:
chars=("", A..Z)
i=26
echo $chars[i] # Z
You can use an array of characters and just specify an index:
chars=("", A..Z)
i=26
echo $chars[i] # Z
answered Mar 28 at 6:26
chorobachoroba
168k17 gold badges148 silver badges219 bronze badges
168k17 gold badges148 silver badges219 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f55391213%2fhow-do-i-translate-1-26-to-a-z-in-bash%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
What will be the output of
./file.sh -u -s 216
?– oguz ismail
Mar 28 at 6:20
well it was unexpected but it gives me BAC
– Juan Pablo
Mar 28 at 6:21
What is the expected output of it?
– oguz ismail
Mar 28 at 6:26
undefined? 216 is greater than 26 so nothing I guess
– Juan Pablo
Mar 28 at 6:34
1
Not easily (if at all) with
tr
.– choroba
Mar 28 at 7:02