Skip to content

Instantly share code, notes, and snippets.

@igrep
Created August 9, 2011 10:55
Show Gist options
  • Save igrep/1133754 to your computer and use it in GitHub Desktop.
Save igrep/1133754 to your computer and use it in GitHub Desktop.
Sample to show that It's more useful to use +eval+ and +source+ if you want to decide which command to execute in your script
#!/bin/bash
#Execute command twice.
#Sample to show that
# It's more useful to use +eval+ and +source+
# if you want to decide which command to execute in your script
shopt -s expand_aliases # don't work even if expand_aliases is enabled.
# $@ #don't work well: don't expand the alias
eval $@
eval $@
#sample
# alias foo='echo foo'
# ./twice.sh foo # do NOT expand the alias!!
# source twice.sh foo # DO expand the alias!!
# alias twice='source twice.sh' # you can use it as a command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment