If the follow strange directory is created:



In bash or zsh one can do: cd a$'\n'b or cd 'a'$'\n''b'

What is the equivalent for dash?


The only equivalent is essentially what you wrote:

cd a"

(or some other arrangement of quotes). String literals can contain whitespace, including line breaks, and preserve it literally as part of the word it's in. You can't use a backslash for the line break because that invokes newline joining and just deletes the line break entirely, so either single or double quotes are your options.

In this case you could also use command substitution with e.g. printf to process that same \n escape sequence:

cd "a$(printf '\nb')"

The final b is required within the printf because trailing newlines are deleted by command substitution, so this won't work if the filename literally ends with newline character. You can also use it for other escapes, such as \a for a BEL byte.

There is no direct POSIX or dash equivalent for $'...' ANSI-C quoting (yet).

  • Thank you Michael, your solution provided a useable workaround. – TrevorTheDev Jan 31 at 5:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.