You are not logged in.

#1 2023-08-28 12:00:56

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

Back again :D, for some advice [Solved]

Hey again Archlinux forum.
I hope to gain some insight and advice as to what i should do, to solve my problem.
Context:
I have made a code for runining executeable files that are not normally does not have an executeable commandline.
The code works, to some extend.

What i want advice for:
1. Is there a way to index the lines or ID Names, of the applications, so that i can just use the ID number from a list and then it removes that,
2. if i can make a liste with something like:

 ["IndexID1:$NameOfSomething, LineNr.$1=50-55", "IndexID2:$NameOfSomething, LineNr.$2=60-65", etc....] 

  That can take and hold a number ID that don't chance, but a lineNumber, that chances depending on what is added or removed from the list.
3. anything i have not considered, and i should watch out for, or make as chances?

The Code (before test use):

#!/usr/bin/env bash 
#Costum commands for user
function OptionsToRC() {
	###
	#echo $@		#For debugging to see what gets paste to function
	FileName=.costumBashCommands.bash
	Name=$1
	Message=$2
	Path=$3
	LineNr=53
	### Start of Switch
	case $Options in
		"Add" )	
			Add='\		'$Name' )\n			echo -e '$Message';\n 			exec '$Path';\n 			return\n 			;;\n '
			sed -i "$LineNr i $Add" $FileName;
			echo Done add;
			source $FileName
			;;
		"Remove" )
			Remove='\	"$Name" )\n			echo -e  "$Message";\n			exec $Path;\n			return\n			;;\n '
			sed -i "$LineNr i $Remove" $FileName;
			echo Done remove;
			source $FileName
			;;
	esac
}

function runCommands() {
	###VARIABLES
	Input=$1
	Options=$2
	Path=$5
	Message=$4
	Name=$3
	### Start of Switch
	case $Input in 
 

		"$Name" )
		echo -e "Run Discord";
		exec /home/$Name/To/Some/Where;
		return
		;;

		"Options" )
			OptionsToRC "$Name" "$Message" "$Path"
		;;
		"Help" )
			echo -e	"Usage: runCommands(Argument1:Name-Of-Applications/Options/Help, Argument2: Add/Remove, Argument3: Name-Of-Application-To-Add/Remove, Argument4:Message-for-Application, Argument5:Path-for-Applications)"
		;;
		*)
		echo -e "error in the given arguments";
		echo -e "Usage wrong {Name|Optines}";
		;;

	esac
}

Code after UserInput:

#!/usr/bin/env bash 
#Costum commands for user
function OptionsToRC() {
	###
	#echo $@		#For debugging to see what gets paste to function
	FileName=.costumBashCommands.bash
	Name=$1
	Message=$2
	Path=$3
	LineNr=53
	### Start of Switch
	case $Options in
		"Add" )	
			Add='\		'$Name' )\n			echo -e '$Message';\n 			exec '$Path';\n 			return\n 			;;\n '
			sed -i "$LineNr i $Add" $FileName;
			echo Done add;
			source $FileName
			;;
		"Remove" )
			Remove='\	"$Name" )\n			echo -e  "$Message";\n			exec $Path;\n			return\n			;;\n '
			sed -i "$LineNr i $Remove" $FileName;
			echo Done remove;
			source $FileName
			;;
	esac
}

function runCommands() {
	###VARIABLES
	Input=$1
	Options=$2
	Path=$5
	Message=$4
	Name=$3
	### Start of Switch
	case $Input in 
 
		FakeMariocarTest )
			echo -e A fake version of mariocar;
 			exec /home/$NameOfUser/Path/To/Somewhere;
 			return
 			;;
 

		"$Name" )
		echo -e "Run Discord";
		exec /home/$Name/To/Some/Where;
		return
		;;

		"Options" )
			OptionsToRC "$Name" "$Message" "$Path"
		;;
		"Help" )
			echo -e	"Usage: runCommands(Argument1:Name-Of-Applications/Options/Help, Argument2: Add/Remove, Argument3: Name-Of-Application-To-Add/Remove, Argument4:Message-for-Application, Argument5:Path-for-Applications)"
		;;
		*)
		echo -e "error in the given arguments";
		echo -e "Usage wrong {Name|Optines}";
		;;

	esac
}

Last edited by ELODollZ (2023-08-30 09:32:35)

Offline

#2 2023-08-28 12:11:35

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Back again :D, for some advice [Solved]

Why do you want to do this?  Just put scripts into a folder included in your PATH.  Then you can add and remove scripts as you wish without having to maintain a messy .costumeBashCommands.bash file along with this error-prone script.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2023-08-29 07:26:10

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

Re: Back again :D, for some advice [Solved]

dang, didn't know you could just add, but how would you execute a file then?
i feel like there is a lot skipped/maybe im to dumb to understand, in the wiki. -_--

Last edited by ELODollZ (2023-08-29 07:38:22)

Offline

#4 2023-08-29 12:41:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Back again :D, for some advice [Solved]

ELODollZ wrote:

but how would you execute a file then

Assuming it's an executable script, you'd just type it's name on the command line and hit enter.  If this is a new idea to you arch linux is not a good choice - if you're going to stick with arch, you need to understand how the basics of a linux/unix system work.  I'd recommend working through at least the first couple tutorials here:

https://ryanstutorials.com


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2023-08-30 07:49:25

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

Re: Back again :D, for some advice [Solved]

either i'm dumb, or it doesn't work, the way i want it to.
The intend of the code i made, was to just have a keyword, i use discords.exe for a reference.
So that i can call open an executeable, from anywhere in the system. my point is that, even if im in the root folder, or the sub-folder-20 of my file system that i can call the executeable.
But just adding the exe to a directory, and adding that directory to the path, doesn't work. i assume from your explantion, that i would just need to "discord.exe" to make it run, but it doesn't.

Offline

#6 2023-08-30 08:19:47

dogknowsnx
Member
Registered: 2021-04-12
Posts: 652

Re: Back again :D, for some advice [Solved]

ELODollZ wrote:

But just adding the exe to a directory, and adding that directory to the path, doesn't work.

https://bbs.archlinux.org/viewtopic.php?id=57855

https://wiki.archlinux.org/title/Environment_variables


RI - Rest your Eyes and Self

"We are eternal, all this pain is an illusion" - Maynard James Keenan

Offline

#7 2023-08-30 09:32:00

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

Re: Back again :D, for some advice [Solved]

Omg, i feel so dumb.....
I forgot capital letter..... to make it work....

Offline

Board footer

Powered by FluxBB