1

Can the .bash_aliases file accept an alias that is of the form of alias #='./'

I've tried quotes and escaping the character too, but it doesn't seem to work.

  • Maybe it's a bug in bash? In zsh works. – rudimeier Nov 1 '16 at 18:51
  • What are you trying to solve ? # is start of shell comment. So alias #='./' is equivalent to invoke alias command with some comment in right side. Regarding to zsh mentioned in comment above, please refer this, unix.stackexchange.com/a/33995/64403 – 林果皞 Nov 1 '16 at 18:58
  • I wanted to make # as the command line command to execute a C object file. So instead of ./name_of_file arg1 arg2 I type in #name_of_file arg1 arg2 – svaze Nov 14 '16 at 20:09
4

Do this :

xb@dnxb:~/tmp$ shopt interactive_comments
interactive_comments    on
xb@dnxb:~/tmp$ shopt -u interactive_comments
xb@dnxb:~/tmp$ shopt interactive_comments
interactive_comments    off
xb@dnxb:~/tmp$ alias #='ls -la'
xb@dnxb:~/tmp$ # /tmp -d
drwxrwxrwt 14 root root 32768 Nov  2 03:09 /tmp
xb@dnxb:~/tmp$ 

In ~/.bash_aliases, escape it:

shopt -u interactive_comments
alias \#='ls -la'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.