The program takes single character as an argument.
./myprog <character>
How can i pass \n in the shell to the myprog ?
The program takes single character as an argument.
./myprog <character>
How can i pass \n in the shell to the myprog ?
Easiest but not very pretty:
./myprog "
"
EDIT: Still easiest, but I forgot about it:
./myprog $'\n'
Another alternative:
./myprog ^M # not ^ and M, but the literal LF character
# in `bash`, obtained by Ctrl-V, Enter
Or, you can do what these programs do, and parse the argument yourself. If you say ./myprog "\n"
, your code will receive the two-character string \n
as its first argument - look for such a sequence and translate it to a newline (e.g. by passing the argument through printf
or equivalent in your language, or by regular expression substitution...).