You are not logged in.
Pages: 1
Hey Arch forum.
Don't know if this is the correct place to ask, i will remove if not.
EDIT:
Forgot to add, the script semi works, my argument is just never used, it allways goes to the last pattern and output "error in the given arguments"
Context:
Trying to make a costum bash command where i can add future executeablefiles to.
This is what i have so far:
function runCommands() {
case $(($Name)) in
[$Name = COSTUMNAME]
echo -n "Run COSTUMNAME"
RunCOSTUM="/PATH/TO/SOME/WHERE/IN/COMPUTER && exit"
ReOpenTerminal="executing ssh user@machine"
;;
[$Name = "Optiones" ])
echo -n "testing"
;;
(*)
echo -n "error in the given arguments"
;;
esac
}P.S i will remove if its not okay to ask here, i'm fairly new to arch and bash
Last edited by ELODollZ (2023-02-13 10:54:22)
Offline
1. I don't understand what this is supposed to do.
2. It's just a function, not a full script.
3. You're missing at least one ) and have one ( too much.
4. What are those square brackets in the case patterns?
case $PET in
Cat)
echo "cat"
;;
Dog)
echo "dog"
;;
Bird)
echo "bird"
;;
*)
echo "Wouldn't pet"
;;
esacOffline
Awebb:
1. So i'm i wanna make a CLI where i can add future executeable files, for games/GUI i plan to make, but i don't want to go into the folders (very long path finding to find a single exe to run a program) So i wanna make a script that is allways callable, the usesage i want is something like:
runCommand runABallGame
#to add a exe
runCommand runABallGame -P ~/Home/NAME/Path/To/Somewhere/In/Computer/2. so far the function is the only thing i got.
3.
Updated:
function runCommands() {
case $(($Name)) in
[ $Name = COSTUMNAME ])
echo -n "Run COSTUMNAME"
RunCOSTUM="/PATH/TO/SOME/WHERE/IN/COMPUTER && exit"
ReOpenTerminal="executing ssh user@machine"
;;
[ $Name = "Optiones" ])
echo -n "testing"
;;
(*))
echo -n "error in the given arguments"
;;
esac
}4. i found a documentation where, brackets is used for when you want to compare an argument with a string (i might be using it wrong i don't know)
Offline
The square brackets can be used for globbing in the case context, but not as alias for test and test doesn't make any sense here, since you're matching using case.
Read https://tldp.org/LDP/Bash-Beginners-Guide/html/ from start to finish
but i don't want to go into the folders (very long path finding to find a single exe to run a program) So i wanna make a script that is allways callable, the usesage i want is something like:
You maybe also want to look into the $PATH environment variable and if the $PWD isn't relevant, you can simply symlink the executables into a $PATH
Offline
[SOLVED]
-Seth
Thanks for the help.
made the code work, if anyone else needs an executeable runcommand:
###runCommands for ExecuateableFiles
runCommands() {
###VARIABLES
VARIABLE=$@
### Start of Switch
case $VARIABLE in
"NAMEOFSOMETHING")
echo -e "Run NAMEOFSOMETHING"
exec /PATH/TO/SOME/WHERE/ON/COMPUTER;
return
;;
###Adding optiones later
Optiones*)
echo -e "testing" ;
return
#exit 128
;;
*)
echo -e "error in the given arguments";
echo "Usage wrong {Name|Optines}"
#exit 1
esac
}Sources:
https://linuxize.com/post/how-to-compar … s-in-bash/
https://tldp.org/LDP/Bash-Beginners-Guide/html/
Last edited by ELODollZ (2023-02-13 10:52:41)
Offline
$@ is the unquoted array of parameters you probably don't want to test against that and you also don't need to copy it into "VARIABLE" this way what effectively just results in $1
…
###runCommands for ExecuateableFiles
runCommands() {
### Start of Switch
case "$1" in
"NAMEOFSOMETHING")
…You still got a lot to read ahead of you ![]()
Offline
Pages: 1