Skip to main content
2 of 5
Formatted text. Grammar. Spelling. Added tag.
Paulo Tomé
  • 3.9k
  • 6
  • 28
  • 40

Executing alias string command

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?

Leo
  • 103
  • 4