0

I use to type this command a lot :

sshfs 10.xxx.xx.4:/Users/username/code mountpoint

So one day i put it as an alias on my .bash_profile as

alias sshfs='sshfs 10.xxx.xx.4:/Users/username/code mountpoint'

and started to use the alias all the time

i have noticed that now after a few months if i copy/type the command directly into the terminal i get "Fuse: invalid argument" error but if i continue to use the alias it works fine.

What's going on here?

  • 2
    It's always using the alias. Thus, when you type in sshfs 10.xxx.xx.4:/Users/username/code mountpoint, it expands the alias and winds up trying to run sshfs 10.xxx.xx.4:/Users/username/code mountpoint 10.xxx.xx.4:/Users/username/code mountpoint, and the extra arguments cause sshfs to complain. You need to name the alias something different from the command to avoid this confusion. – Gordon Davisson Oct 17 '19 at 23:07
0

Always use a different name for your alias. For example (one of mine):

alias ipex='curl -s http://ipecho.net/plain'

Or, in your case:

alias s4='sshfs 10.xxx.xx.4:/Users/username/code mountpoint'
alias s8='sshfs 10.xxx.xx.8:/Users/username/code mountpoint'

and so on.

You may use more complex aliases, or even personal functions used inside aliases, for example when you need to pass a parameter inside the command, not at the end (as to provide a changing IP address to your alias), but it is probably a bit too much depending on your question.

Anyway, this is one of mine, again:

# Delete an existing alias, but only if it exists in order to avoid an error:
dont_alias() {
    alias $1 >/dev/null 2>&1 && unalias $1
    return $?
} # dont_alias

Then I use dont_alias as an alias, for example:

dont_alias s4 # Will unalias the existing s4
dont_alias s7 # Will do nothing

The only difference with aliases is that functions do not appear in the list of (existing) aliases.

I have a few more complex samples (that I use daily), if some people are interested. Please feel free to ask for — I do my best to come here every few days :^)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .