Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore $ in first of commands

Tags:

bash

terminal

How can I write a function that Bash ignores $ in first of commands? I want this because sometimes when I paste a command from web it includes a $ in first character.

$ ls should do ls or $ grep 'foo' should do grep 'foo'.

This will not work because $ is not a valid function name.

function $ {
   ...
} 
like image 830
Mohsen Avatar asked Jan 03 '13 18:01

Mohsen


1 Answers

Create a file called $ somewhere on your $PATH, e.g. in ~/bin:

cd ~/bin
cat <<'EOF' > \$
#!/bin/sh
"$@"
EOF

Make it executable:

chmod 755 \$

And enjoy the madness:

$ ls -l
total 92
-rwxr-xr-x 1 thomas thomas    13 Jan  3 19:09 $
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ ls
total 92
-rwxr-xr-x 1 thomas thomas    13 Jan  3 19:09 $
like image 55
Thomas Avatar answered Oct 31 '22 19:10

Thomas