I would like to declare a few shortcut commands to switch between my various coding projects, so I have come up with the following script.
projects=$(ls -d ~/Workspace/*/)
prefix="/Users/myuser/Workspace/"
for f in $projects
do
temp=${f#$prefix}
temp=${temp/%\//}
c="alias $temp='cd $f'"
echo $c
eval $c
done
I put that in a file called .workspace-shotcuts.sh
in my homefolder, then I chmod +X .workspace-shotcuts.sh
it.
when I run it, using ./.workspace-shotcuts.sh
I get
alias project1='cd /Users/myuser/Workspace/project1/'
alias project2='cd /Users/myuser/Workspace/project2/'
in the console. But the aliases are not declare (zsh: command not found: project1
).
Also at the end of my .zshrc
file I have added /bin/sh .workspace-shotcuts.sh
, which gives the same output, but still no aliases.
Any body can tell me what I am missing? I would like to point out that I am not a great *nix user, so you might have to ELI5 some things to me.
EDIT:
I was suggested to use source
instead, which I have done, but here is the error messages I get:
(eval):2: permission denied: /Users/myuser/Workspace/project1/
(eval):3: permission denied: /Users/myuser/Workspace/project2/
(eval):4: permission denied: /Users/myuser/Workspace/project3/
(eval):5: permission denied: /Users/myuser/Workspace/project4/
(eval):6: permission denied: /Users/myuser/Workspace/project5/
(eval):7: permission denied: /Users/myuser/Workspace/project6/
(eval):8: permission denied: /Users/myuser/Workspace/project7/
(eval):9: no such file or directory: /Users/myuser/Workspace/project1=cd /Users/myuser/Workspace/project1/\n/Users/myuser/Workspace/project2/\n/Users/myuser/Workspace/project3/\n/Users/myuser/Workspace/project4/\n/Users/myuser/Workspace/project5/\n/Users/myuser/Workspace/project6/\n/Users/myuser/Workspace/project7/
What is happening? Is there some special permission I need to give my script?
source
, I do not think it fixed much. – le-doude Dec 13 '15 at 06:07zsh
, but it looks like you're having a problem with a difference betweenzsh
and/bin/sh
. Try runningzsh .workspace-shotcuts.sh
; it will probably fail the same as thesource
command. Then look atzsh
documentation to figure out what you need to change to get it to work inzsh
. Thensource .workspace-shotcuts.sh
should work. – G-Man Says 'Reinstate Monica' Dec 13 '15 at 08:13