Search code examples
linuxbashscreenshotaliasmv

Alias to Scrot program doesn't work in .bashrc but works in terminal


I'm trying to alias a scrot command in .bashrc with this:

alias scrotn="scrot %Y-%m-%d-%s_$wx$h.jpg -e 'mv $f ~/pictures/screenshots/'"

The scrot command works in my terminal but when I try to run scrotn i receive this output:

mv: missing destination file operand after '/home/lain/pictures/screenshots/'

Already tried adding quotes to %Y-%m-%d-%s_$wx$h.jpg, switching double and single quotes and using /home/lain/ instead of ~/. Yes, ~/pictures/screenshots/ exists. I wanna create an alias to bind it to the PrtSc key in my DWM config. Sorry for poor english.


Solution

  • Since the alias is defined as a double-quoted string (the inner quotes do not matter for the shell) $f is expanded (presumably to the empty string) when the alias is created. The recommended way to work around this would be to use a function rather than an alias. Aliases are considered deprecated by many, because they can do less than functions, are hard to debug as you've discovered, and are really not much simpler than functions.

    The result:

    scrotn() {
        [your scrot command line]
    }