DOS command to Bash command conversion
I need to make Bash take DOS commands in with arguments and then convert the main command to a Bash command and still use the arguments if there are any arguments.
The part I am lost on is how to pass arguments to the individual cases and not getting stuck by the *) Command Not Found!
For example a user inputs:
copy file1.txt file2.txt
Use case: copy then should run the Linux cp command and use the two arguments passed copy to finish the command.
#!/bin/bash
while :
do
read INPUT_STRING
case $INPUT_STRING in
chdir|CHDIR)
cd $arg1
bash myscript.sh
;;
cls|CLS)
clear
bash myscript.sh
;;
copy|COPY)
cp $arg1 $arg2
bash myscript.sh
;;
createdir|CREATEDIR)
mkdir $arg1
bash myscript.sh
;;
delete|DELETE)
rm $arg1
bash myscript.sh
;;
dir|DIR)
ls
bash myscript.sh
;;
move|MOVE)
mv $arg1 $arg2
bash myscript.sh
;;
print|PRINT)
echo $arg1
bash myscript.sh
;;
quit|QUIT)
break
PS1="n01396736@cisvm-cop4640-2:~$ "
;;
rename|RENAME)
mv $arg1 $arg2
bash myscript.sh
;;
type|TYPE)
cat $arg1
bash myscript.sh
;;
*)
echo "Command Not Found!!"
bash myscript.sh
;;
esac
break
done
linux bash arguments case
New contributor
Trinity Zamrzla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I need to make Bash take DOS commands in with arguments and then convert the main command to a Bash command and still use the arguments if there are any arguments.
The part I am lost on is how to pass arguments to the individual cases and not getting stuck by the *) Command Not Found!
For example a user inputs:
copy file1.txt file2.txt
Use case: copy then should run the Linux cp command and use the two arguments passed copy to finish the command.
#!/bin/bash
while :
do
read INPUT_STRING
case $INPUT_STRING in
chdir|CHDIR)
cd $arg1
bash myscript.sh
;;
cls|CLS)
clear
bash myscript.sh
;;
copy|COPY)
cp $arg1 $arg2
bash myscript.sh
;;
createdir|CREATEDIR)
mkdir $arg1
bash myscript.sh
;;
delete|DELETE)
rm $arg1
bash myscript.sh
;;
dir|DIR)
ls
bash myscript.sh
;;
move|MOVE)
mv $arg1 $arg2
bash myscript.sh
;;
print|PRINT)
echo $arg1
bash myscript.sh
;;
quit|QUIT)
break
PS1="n01396736@cisvm-cop4640-2:~$ "
;;
rename|RENAME)
mv $arg1 $arg2
bash myscript.sh
;;
type|TYPE)
cat $arg1
bash myscript.sh
;;
*)
echo "Command Not Found!!"
bash myscript.sh
;;
esac
break
done
linux bash arguments case
New contributor
Trinity Zamrzla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
What are you expectingbash myscript.shat the end of each case branch to do? I think you're trying to loop, but you're actually calling the script from itself over and over again. Remove thebreakat the end and strip out all thesebash myscript.shstatements.
– roaima
1 hour ago
1
Quote those variables. Quote those variables. Quote those variables. (For examplemv $arg1 $arg2should be rewritten asmv "$arg1" "$arg2")
– roaima
1 hour ago
I need it to continue to loop until user types quit or QUIT. with a single break in the quit|QUIT) case it didn't send the user back the terminal/command prompt out of the bash. As far as the bash myscript.sh I had issues where it would run dir and then drop the user to back to the terminal/command prompt out of the bash.
– Trinity Zamrzla
1 hour ago
I added the quotes around all the $arg1 and $arg2. I am still getting the same error that when I input copy file1.txt file2.txt my catch all *) responds with Command Not Found!! which is a good thing that it is working, however, I need the arguments to be sued inside the case. In java or C I could separate the input by white space and then store them into an array and then increment through the array to read each section separately.
– Trinity Zamrzla
1 hour ago
Thank you for the hit about the quotes I got it working now. read command arg1 arg2 arg3 case "$command" in then I am using "$arg1" to "$arg3" as needed
– Trinity Zamrzla
9 mins ago
add a comment |
I need to make Bash take DOS commands in with arguments and then convert the main command to a Bash command and still use the arguments if there are any arguments.
The part I am lost on is how to pass arguments to the individual cases and not getting stuck by the *) Command Not Found!
For example a user inputs:
copy file1.txt file2.txt
Use case: copy then should run the Linux cp command and use the two arguments passed copy to finish the command.
#!/bin/bash
while :
do
read INPUT_STRING
case $INPUT_STRING in
chdir|CHDIR)
cd $arg1
bash myscript.sh
;;
cls|CLS)
clear
bash myscript.sh
;;
copy|COPY)
cp $arg1 $arg2
bash myscript.sh
;;
createdir|CREATEDIR)
mkdir $arg1
bash myscript.sh
;;
delete|DELETE)
rm $arg1
bash myscript.sh
;;
dir|DIR)
ls
bash myscript.sh
;;
move|MOVE)
mv $arg1 $arg2
bash myscript.sh
;;
print|PRINT)
echo $arg1
bash myscript.sh
;;
quit|QUIT)
break
PS1="n01396736@cisvm-cop4640-2:~$ "
;;
rename|RENAME)
mv $arg1 $arg2
bash myscript.sh
;;
type|TYPE)
cat $arg1
bash myscript.sh
;;
*)
echo "Command Not Found!!"
bash myscript.sh
;;
esac
break
done
linux bash arguments case
New contributor
Trinity Zamrzla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I need to make Bash take DOS commands in with arguments and then convert the main command to a Bash command and still use the arguments if there are any arguments.
The part I am lost on is how to pass arguments to the individual cases and not getting stuck by the *) Command Not Found!
For example a user inputs:
copy file1.txt file2.txt
Use case: copy then should run the Linux cp command and use the two arguments passed copy to finish the command.
#!/bin/bash
while :
do
read INPUT_STRING
case $INPUT_STRING in
chdir|CHDIR)
cd $arg1
bash myscript.sh
;;
cls|CLS)
clear
bash myscript.sh
;;
copy|COPY)
cp $arg1 $arg2
bash myscript.sh
;;
createdir|CREATEDIR)
mkdir $arg1
bash myscript.sh
;;
delete|DELETE)
rm $arg1
bash myscript.sh
;;
dir|DIR)
ls
bash myscript.sh
;;
move|MOVE)
mv $arg1 $arg2
bash myscript.sh
;;
print|PRINT)
echo $arg1
bash myscript.sh
;;
quit|QUIT)
break
PS1="n01396736@cisvm-cop4640-2:~$ "
;;
rename|RENAME)
mv $arg1 $arg2
bash myscript.sh
;;
type|TYPE)
cat $arg1
bash myscript.sh
;;
*)
echo "Command Not Found!!"
bash myscript.sh
;;
esac
break
done
linux bash arguments case
linux bash arguments case
New contributor
Trinity Zamrzla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Trinity Zamrzla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 5 mins ago
Michael Prokopec
1,458218
1,458218
New contributor
Trinity Zamrzla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 1 hour ago
Trinity ZamrzlaTrinity Zamrzla
64
64
New contributor
Trinity Zamrzla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Trinity Zamrzla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Trinity Zamrzla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
What are you expectingbash myscript.shat the end of each case branch to do? I think you're trying to loop, but you're actually calling the script from itself over and over again. Remove thebreakat the end and strip out all thesebash myscript.shstatements.
– roaima
1 hour ago
1
Quote those variables. Quote those variables. Quote those variables. (For examplemv $arg1 $arg2should be rewritten asmv "$arg1" "$arg2")
– roaima
1 hour ago
I need it to continue to loop until user types quit or QUIT. with a single break in the quit|QUIT) case it didn't send the user back the terminal/command prompt out of the bash. As far as the bash myscript.sh I had issues where it would run dir and then drop the user to back to the terminal/command prompt out of the bash.
– Trinity Zamrzla
1 hour ago
I added the quotes around all the $arg1 and $arg2. I am still getting the same error that when I input copy file1.txt file2.txt my catch all *) responds with Command Not Found!! which is a good thing that it is working, however, I need the arguments to be sued inside the case. In java or C I could separate the input by white space and then store them into an array and then increment through the array to read each section separately.
– Trinity Zamrzla
1 hour ago
Thank you for the hit about the quotes I got it working now. read command arg1 arg2 arg3 case "$command" in then I am using "$arg1" to "$arg3" as needed
– Trinity Zamrzla
9 mins ago
add a comment |
1
What are you expectingbash myscript.shat the end of each case branch to do? I think you're trying to loop, but you're actually calling the script from itself over and over again. Remove thebreakat the end and strip out all thesebash myscript.shstatements.
– roaima
1 hour ago
1
Quote those variables. Quote those variables. Quote those variables. (For examplemv $arg1 $arg2should be rewritten asmv "$arg1" "$arg2")
– roaima
1 hour ago
I need it to continue to loop until user types quit or QUIT. with a single break in the quit|QUIT) case it didn't send the user back the terminal/command prompt out of the bash. As far as the bash myscript.sh I had issues where it would run dir and then drop the user to back to the terminal/command prompt out of the bash.
– Trinity Zamrzla
1 hour ago
I added the quotes around all the $arg1 and $arg2. I am still getting the same error that when I input copy file1.txt file2.txt my catch all *) responds with Command Not Found!! which is a good thing that it is working, however, I need the arguments to be sued inside the case. In java or C I could separate the input by white space and then store them into an array and then increment through the array to read each section separately.
– Trinity Zamrzla
1 hour ago
Thank you for the hit about the quotes I got it working now. read command arg1 arg2 arg3 case "$command" in then I am using "$arg1" to "$arg3" as needed
– Trinity Zamrzla
9 mins ago
1
1
What are you expecting
bash myscript.sh at the end of each case branch to do? I think you're trying to loop, but you're actually calling the script from itself over and over again. Remove the break at the end and strip out all these bash myscript.sh statements.– roaima
1 hour ago
What are you expecting
bash myscript.sh at the end of each case branch to do? I think you're trying to loop, but you're actually calling the script from itself over and over again. Remove the break at the end and strip out all these bash myscript.sh statements.– roaima
1 hour ago
1
1
Quote those variables. Quote those variables. Quote those variables. (For example
mv $arg1 $arg2 should be rewritten as mv "$arg1" "$arg2")– roaima
1 hour ago
Quote those variables. Quote those variables. Quote those variables. (For example
mv $arg1 $arg2 should be rewritten as mv "$arg1" "$arg2")– roaima
1 hour ago
I need it to continue to loop until user types quit or QUIT. with a single break in the quit|QUIT) case it didn't send the user back the terminal/command prompt out of the bash. As far as the bash myscript.sh I had issues where it would run dir and then drop the user to back to the terminal/command prompt out of the bash.
– Trinity Zamrzla
1 hour ago
I need it to continue to loop until user types quit or QUIT. with a single break in the quit|QUIT) case it didn't send the user back the terminal/command prompt out of the bash. As far as the bash myscript.sh I had issues where it would run dir and then drop the user to back to the terminal/command prompt out of the bash.
– Trinity Zamrzla
1 hour ago
I added the quotes around all the $arg1 and $arg2. I am still getting the same error that when I input copy file1.txt file2.txt my catch all *) responds with Command Not Found!! which is a good thing that it is working, however, I need the arguments to be sued inside the case. In java or C I could separate the input by white space and then store them into an array and then increment through the array to read each section separately.
– Trinity Zamrzla
1 hour ago
I added the quotes around all the $arg1 and $arg2. I am still getting the same error that when I input copy file1.txt file2.txt my catch all *) responds with Command Not Found!! which is a good thing that it is working, however, I need the arguments to be sued inside the case. In java or C I could separate the input by white space and then store them into an array and then increment through the array to read each section separately.
– Trinity Zamrzla
1 hour ago
Thank you for the hit about the quotes I got it working now. read command arg1 arg2 arg3 case "$command" in then I am using "$arg1" to "$arg3" as needed
– Trinity Zamrzla
9 mins ago
Thank you for the hit about the quotes I got it working now. read command arg1 arg2 arg3 case "$command" in then I am using "$arg1" to "$arg3" as needed
– Trinity Zamrzla
9 mins ago
add a comment |
0
active
oldest
votes
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
});
}
});
Trinity Zamrzla is a new contributor. Be nice, and check out our Code of Conduct.
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%2f500747%2fdos-command-to-bash-command-conversion%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Trinity Zamrzla is a new contributor. Be nice, and check out our Code of Conduct.
Trinity Zamrzla is a new contributor. Be nice, and check out our Code of Conduct.
Trinity Zamrzla is a new contributor. Be nice, and check out our Code of Conduct.
Trinity Zamrzla is a new contributor. Be nice, and check out our Code of Conduct.
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.
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%2f500747%2fdos-command-to-bash-command-conversion%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
1
What are you expecting
bash myscript.shat the end of each case branch to do? I think you're trying to loop, but you're actually calling the script from itself over and over again. Remove thebreakat the end and strip out all thesebash myscript.shstatements.– roaima
1 hour ago
1
Quote those variables. Quote those variables. Quote those variables. (For example
mv $arg1 $arg2should be rewritten asmv "$arg1" "$arg2")– roaima
1 hour ago
I need it to continue to loop until user types quit or QUIT. with a single break in the quit|QUIT) case it didn't send the user back the terminal/command prompt out of the bash. As far as the bash myscript.sh I had issues where it would run dir and then drop the user to back to the terminal/command prompt out of the bash.
– Trinity Zamrzla
1 hour ago
I added the quotes around all the $arg1 and $arg2. I am still getting the same error that when I input copy file1.txt file2.txt my catch all *) responds with Command Not Found!! which is a good thing that it is working, however, I need the arguments to be sued inside the case. In java or C I could separate the input by white space and then store them into an array and then increment through the array to read each section separately.
– Trinity Zamrzla
1 hour ago
Thank you for the hit about the quotes I got it working now. read command arg1 arg2 arg3 case "$command" in then I am using "$arg1" to "$arg3" as needed
– Trinity Zamrzla
9 mins ago