Skip to main content
Added proper answer to OP's question; minor changes
Source Link
fra-san
  • 10.9k
  • 2
  • 27
  • 45

You may set the alias by assigning a string wrapped in single quotes to latestbotlogs, as in:

alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'

where the expression \' is used to protect single quotes from the shell and have them concatenated in the resulting command. You can verify that they are preserved:

$ alias latestbotlogs
alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'''

While with your alias:

alias latestbotlogs="ssh user@hostname 'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

gives an error upon definition because the command substitution is evaluated immediately, upon definition. This happens because single quotes lose their special meaning when escaped (with \) or enclosed in double quotes ("). (Reference: Quoting in "The Open Group Base Specifications Issue 7, 2018 edition").
And this is the key: single quotes around the remote command are enough to protect it when the alias is invoked, but do not prevent the enclosed command to be substituted when the alias is created.

Indeed youYou can also use "'" as an alternative to \', as in:

alias latestbotlogs='ssh user@hostname '"'"'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"'"

Or, using enclose the whole command in double quotes and add some escaping:

alias latestbotlogs="ssh user@hostname 'tail -f \$(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

WhereIn this last form, all the characters that retain a special meaning when double-quoted ($, ` and </code>) have to be escaped (here we have only a $).

Your function, instead, should just work.

You may set the alias by assigning a string wrapped in single quotes to latestbotlogs, as in:

alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'

where the expression \' is used to protect single quotes from the shell and have them concatenated in the resulting command. You can verify that they are preserved:

$ alias latestbotlogs
alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'''

While your alias:

alias latestbotlogs="ssh user@hostname 'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

gives an error upon definition because the command substitution is evaluated immediately. This happens because single quotes lose their special meaning when escaped (with \) or enclosed in double quotes ("). (Reference: Quoting in "The Open Group Base Specifications Issue 7, 2018 edition").

Indeed you can use "'" as an alternative to \', as in:

alias latestbotlogs='ssh user@hostname '"'"'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"'"

Or, using double quotes:

alias latestbotlogs="ssh user@hostname 'tail -f \$(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

Where all the characters that retain a special meaning when double-quoted ($, ` and </code>) have to be escaped here we have only a $.

Your function, instead, should just work.

You may set the alias by assigning a string wrapped in single quotes to latestbotlogs, as in:

alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'

where the expression \' is used to protect single quotes from the shell and have them concatenated in the resulting command. You can verify that they are preserved:

$ alias latestbotlogs
alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'''

While with your alias:

alias latestbotlogs="ssh user@hostname 'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

the command substitution is evaluated immediately, upon definition. This happens because single quotes lose their special meaning when escaped (with \) or enclosed in double quotes ("). (Reference: Quoting in "The Open Group Base Specifications Issue 7, 2018 edition").
And this is the key: single quotes around the remote command are enough to protect it when the alias is invoked, but do not prevent the enclosed command to be substituted when the alias is created.

You can also use "'" as an alternative to \':

alias latestbotlogs='ssh user@hostname '"'"'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"'"

Or enclose the whole command in double quotes and add some escaping:

alias latestbotlogs="ssh user@hostname 'tail -f \$(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

In this last form, all the characters that retain a special meaning when double-quoted ($, ` and </code>) have to be escaped (here we have only a $).

Your function, instead, should just work.

Added further alternative
Source Link
fra-san
  • 10.9k
  • 2
  • 27
  • 45

You may set the alias by assigning a string wrapped in single quotes to latestbotlogs, as in:

alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'

where the expression \' is used to protect single quotes from the shell and have them concatenated in the resulting command. You can verify that they are preserved:

$ alias latestbotlogs
alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'''

While your alias:

alias latestbotlogs="ssh user@hostname 'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

gives an error upon definition because the command substitution is evaluated immediately. This happens because single quotes lose their special meaning when escaped (with \) or enclosed in double quotes ("). (Reference: Quoting in "The Open Group Base Specifications Issue 7, 2018 edition").

Indeed you can use "'" as an alternative to \', as in:

alias latestbotlogs='ssh user@hostname '"'"'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"'"

Or, using double quotes:

alias latestbotlogs="ssh user@hostname 'tail -f \$(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

Where all the characters that retain a special meaning when double-quoted ($, ` and </code>) have to be escaped — here we have only a $.

Your function, instead, should just work.

You may set the alias by assigning a string wrapped in single quotes to latestbotlogs, as in:

alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'

where the expression \' is used to protect single quotes from the shell and have them concatenated in the resulting command. You can verify that they are preserved:

$ alias latestbotlogs
alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'''

While your alias:

alias latestbotlogs="ssh user@hostname 'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

gives an error upon definition because the command substitution is evaluated immediately. This happens because single quotes lose their special meaning when escaped (with \) or enclosed in double quotes ("). (Reference: Quoting in "The Open Group Base Specifications Issue 7, 2018 edition").

Indeed you can use "'" as an alternative to \', as in:

alias latestbotlogs='ssh user@hostname '"'"'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"'"

Your function, instead, should just work.

You may set the alias by assigning a string wrapped in single quotes to latestbotlogs, as in:

alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'

where the expression \' is used to protect single quotes from the shell and have them concatenated in the resulting command. You can verify that they are preserved:

$ alias latestbotlogs
alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'''

While your alias:

alias latestbotlogs="ssh user@hostname 'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

gives an error upon definition because the command substitution is evaluated immediately. This happens because single quotes lose their special meaning when escaped (with \) or enclosed in double quotes ("). (Reference: Quoting in "The Open Group Base Specifications Issue 7, 2018 edition").

Indeed you can use "'" as an alternative to \', as in:

alias latestbotlogs='ssh user@hostname '"'"'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"'"

Or, using double quotes:

alias latestbotlogs="ssh user@hostname 'tail -f \$(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

Where all the characters that retain a special meaning when double-quoted ($, ` and </code>) have to be escaped — here we have only a $.

Your function, instead, should just work.

Added explanations
Source Link
fra-san
  • 10.9k
  • 2
  • 27
  • 45

You may set the alias by assigning a string wrapped in single quotes to latestbotlogs, as in:

alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'

where the expression \' is used to protect single quotes from the shell and have them concatenated in the resulting command. You can verify that they are preserved:

$ alias latestbotlogs
alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'''

While your alias:

alias latestbotlogs="ssh user@hostname 'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

gives an error upon definition because the command substitution is evaluated immediately. This happens because single quotes lose their special meaning when escaped (with \) or enclosed in double quotes ("). (Reference: Quoting in "The Open Group Base Specifications Issue 7, 2018 edition").

Indeed you can use "'" as an alternative to \', as in:

alias latestbotlogs='ssh user@hostname '"'"'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"'"

Your function, instead, should just work.

You may set the alias by assigning a string wrapped in single quotes to latestbotlogs, as in:

alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'

where the expression \' is used to protect single quotes from the shell and have them concatenated in the resulting command. You can verify that they are preserved:

$ alias latestbotlogs
alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'''

While your alias:

alias latestbotlogs="ssh user@hostname 'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

gives an error upon definition because the command substitution is evaluated immediately. This happens because single quotes lose their special meaning when escaped (with \) or enclosed in double quotes ("). (Reference: Quoting in "The Open Group Base Specifications Issue 7, 2018 edition").

Your function, instead, should just work.

You may set the alias by assigning a string wrapped in single quotes to latestbotlogs, as in:

alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'

where the expression \' is used to protect single quotes from the shell and have them concatenated in the resulting command. You can verify that they are preserved:

$ alias latestbotlogs
alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'''

While your alias:

alias latestbotlogs="ssh user@hostname 'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

gives an error upon definition because the command substitution is evaluated immediately. This happens because single quotes lose their special meaning when escaped (with \) or enclosed in double quotes ("). (Reference: Quoting in "The Open Group Base Specifications Issue 7, 2018 edition").

Indeed you can use "'" as an alternative to \', as in:

alias latestbotlogs='ssh user@hostname '"'"'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"'"

Your function, instead, should just work.

Added explanations
Source Link
fra-san
  • 10.9k
  • 2
  • 27
  • 45
Loading
Removed now-useless "edit" notice
Source Link
fra-san
  • 10.9k
  • 2
  • 27
  • 45
Loading
added 130 characters in body
Source Link
fra-san
  • 10.9k
  • 2
  • 27
  • 45
Loading
Source Link
fra-san
  • 10.9k
  • 2
  • 27
  • 45
Loading