I wrote a simple script to go through my development project directory and add an alias shortcut for each one:
shopt -s dotglob #Use shopt -u dotglob to exclude hidden directories
find ~/development/* -prune -type d | while IFS= read -r d; do
cur_dir="${d##*/}"
cmd="alias ${cur_dir}=\"code $d\""
echo "executing: $cmd"
$cmd
done
And the output looks like this:
executing: alias project-1="code /home/my_user/development/project-1"
./alias_for_projects.sh: line 6: alias: /home/my_user/development/project-1": not found
...
If I copy and run the command:
alias project-1="code /home/my_user/development/project-1"
it just works... How do I fix my script?
cmd
, or better yet, just executealias "${cur_dir}"="code $d"
instead of running$cmd
– muru Apr 09 '20 at 11:17alias "${cur_dir}"="code $d"
when I then try to runproject-1
it returnsproject-1: command not found
– Leo Apr 09 '20 at 11:21