You are not logged in.

#1 2023-02-06 11:02:18

ELODollZ
Member
Registered: 2023-02-06
Posts: 35

[SOLVED] RunCommands to ExecuateableFiles

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

#2 2023-02-06 11:57:48

Awebb
Member
Registered: 2010-05-06
Posts: 6,688

Re: [SOLVED] RunCommands to ExecuateableFiles

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"
    ;;
esac

Offline

#3 2023-02-06 12:15:37

ELODollZ
Member
Registered: 2023-02-06
Posts: 35

Re: [SOLVED] RunCommands to ExecuateableFiles

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

#4 2023-02-06 14:54:55

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,393

Re: [SOLVED] RunCommands to ExecuateableFiles

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

#5 2023-02-13 10:51:49

ELODollZ
Member
Registered: 2023-02-06
Posts: 35

Re: [SOLVED] RunCommands to ExecuateableFiles

[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

#6 2023-02-13 11:00:09

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,393

Re: [SOLVED] RunCommands to ExecuateableFiles

$@ 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 wink

Offline

Board footer

Powered by FluxBB