Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating aliases in .bash_profile that run a shell script

Tags:

bash

shell

So I have a script called spotlyrics.sh that I want to be able to run using the command "lyrics" in the terminal.

I have opened up my .bash_profile and am wondering how I can create the alis which 1) finds the script and then 2) executes it

The file is inside a folder called bash at the following path

/Users/username/Documents/bash

What I have so far (inside my bash profile), which doesn't work because I guess it's not "executing" the script.

alias spotlyrics=“/Users/username/Documents/bash/spotlyrics.sh“

I get the following error when running "spotlyrics" in the terminal:

-bash: “/Users/username/Documents/bash/spotlyrics.sh“: No such file or directory

Would love some help, thanks!

like image 606
user2656127 Avatar asked Mar 22 '26 17:03

user2656127


2 Answers

You've been editing your .bash_profile with something that is not a proper text editor. The quotation marks are not ASCII, and therefore not actually quotation marks as far as the shell is concerned.

Instead of beating around the bush with aliasing a script to a name it mostly already has, why not put the script in a directory in PATH and let it be its own command?

mkdir ~/bin
echo 'PATH+=:$HOME/bin' >> ~/.bashrc
mv "/path/to/spotlyrics.sh" ~/bin/spotlyrics && chmod +x ~/bin/spotlyrics

Then restart the shell (log out and back in) and you won't need the alias.

like image 33
kojiro Avatar answered Mar 24 '26 23:03

kojiro