Score:-1

Alias with input

fo flag

pretty new to linux and trying to create an alias that runs a python file here's how it goes.

alias search=("cd /home/SET && python3 /home/SET/search.py")

The only problem is that "search.py" takes and input and it can't be provided due to the parentheses (because I don't wanna change directory to /home/kali/SET Everytime i run it.), So is there anything can i do about it?

guiverc avatar
cn flag
Welcome to Ask Ubuntu! We are sorry, Kali Linux is off-topic. You can use https://forums.kali.org/ but expect them to be very harsh: Kali is intended for experienced GNU/Linux users and users are expected to fix their own problems and only when that fails to have them ask a question with a well-documented problem. Please refer https://askubuntu.com/help/on-topic, Ubuntu and official flavors of Ubuntu (https://ubuntu.com/download/flavours) are on-topic on this site.
Score:0
in flag

Following function should do what you want:

search(){   
cd /home/SET
python3 /home/SET/search.py "$@"
cd -
}

You should execute the command search and give it as many parameters as you want. They'll all be passed to python script. As you can see in the function, I'm getting into the directory /home/set, executing the command and getting back to where I was before the execution. But first you need to execute that function definition in a shell then you can use it (Copy the code I provided and paste it in the terminal). And the way you use it is just like how you'd use an alias. Example:

search arg_1 arg_2

MohaMoney avatar
fo flag
The only problem is i have the parentheses so i can run the command in a different shell environment not affecting my main shell, because I don't wanna change my directory everytime i run this command.
Muhammed Özen avatar
in flag
If you don't want to cd into that directory, then you should include the full path to the program. That way you preserve your current working directory and execute the script at the same time. `cd /home/SET` part of the command is unnecessary. All you have to do is set the following alias: `alias search="python3 /home/SET/search.py"` I'm editing the answer now. Check it out
MohaMoney avatar
fo flag
I thought of that, but "search.py" has a config that it scans for and it must be in the directory you are executing the command from.
Muhammed Özen avatar
in flag
Then you should use a function instead of an alias. I cant put a code in the comment. Please check out my answer again
MohaMoney avatar
fo flag
Thank you very much, I got it working.
Muhammed Özen avatar
in flag
You're very welcome. Glad to be of some help
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.