I have one-line that I want to call using alias.
while printf '%s ' "$(df -P / | awk 'NR==2 { print $(NF-1) }')"; do sleep 30; done
I tried to escape '
like \'
but it didn't work.
What is the correct syntax to use above one-liner in alias?
I have one-line that I want to call using alias.
I tried to escape What is the correct syntax to use above one-liner in alias? |
||||
|
You can check the result with
If |
|||||||
|
You can't escape single quotes whilst still in single quotes because
|
|||||||||||||||
|
While this can be coaxed into an alias, functions are generally preferred. From
Your alias in function form:
That's more readable, and as such more maintainable. |
|||
|
If you want commands that take arguments or interact in any way with their environment, use functions. At least in bash, aliases are expanded when defined, they might act as if they took arguments or used variables. Sometimes. Murphy's law ensures that that won't work when really needed. |
|||
|
You can't use a backslash to escape a single quote inside a single-quoted string because the backslash itself is interpreted literally. You can effectively escape a single quote inside a single-quoted string by writing the 4-character sequence
I wouldn't recommend such a complex alias. Aliases are primarily meant to give a short name to a command, possibly with switches. This goes well beyond their comfort range. Use a function instead.
|
|||
|