# Sys.argv() and "\\n"

**URL:** <https://discuss.ocaml.org/t/sys-argv-and-n/10863>\
**Category:** Learning\
**Created:** [November 25, 2022, 7:04pm UTC](https://discuss.ocaml.org/t/sys-argv-and-n/10863 "2022-11-25T19:04:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gokulhari](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/gokulhari/32/4059_2.png) [@gokulhari](https://discuss.ocaml.org/u/gokulhari)\
**Post date:** [November 25, 2022, 7:04pm UTC](https://discuss.ocaml.org/t/sys-argv-and-n/10863/1 "2022-11-25T19:04:25Z")

</div>

Hi,

I am trying to use the command line to input using Sys.argv, and the newline character seems to be interpreted as a literal instead of a new line.

Example:

```auto
let () = print_endline Sys.argv.(1)

```

And I try to execute using

> ./main.exe “something\n”

Then on printing, it prints the “something\n”, instead of using “\n” to go to the next line. How do fix this?

Thanks,  
Gokul

---

<div class="post-metadata">

**Author:** ![dra27](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dra27/32/5294_2.png) [@dra27](https://discuss.ocaml.org/u/dra27)\
**Post date:** [November 25, 2022, 7:46pm UTC](https://discuss.ocaml.org/t/sys-argv-and-n/10863/2 "2022-11-25T19:46:08Z")

</div>

The problem is in the invocation - the shell doesn’t understand the “\n” in a string cf.,

```auto
dra@thor:~$ echo "something\n"
something\n

```

For the `echo` command, you may be able to add `-e` to achieve this:

```auto
dra@thor:~$ echo -e "something\n"
something

```

For passing a literal newline to something, it depends on the shell. In bash, you can do this with ANSI C-quoting:

```auto
dra@thor:~$ echo $'something\n'
something

```

---

<div class="post-metadata">

**Author:** ![gokulhari](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/gokulhari/32/4059_2.png) [@gokulhari](https://discuss.ocaml.org/u/gokulhari)\
**Post date:** [November 25, 2022, 11:08pm UTC](https://discuss.ocaml.org/t/sys-argv-and-n/10863/3 "2022-11-25T23:08:35Z")

</div>

Thanks, yes this works, I was using bash.

---

<div class="post-metadata">

**Author:** ![Chet\_Murthy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chet_murthy/32/1501_2.png) [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Post date:** [November 26, 2022, 4:27am UTC](https://discuss.ocaml.org/t/sys-argv-and-n/10863/4 "2022-11-26T04:27:06Z")

</div>

I feel like it’s relevant to note that expecting useful preservation of whitespace, newlines, etc, in shells and shell-based manipulation, is fraught with problems. I mean, sure if you work hard at it, you can usually make it work. But it’s not worth the candle. Better to just assume whitespace is not preserved varbatim. Ditto with the many different kinds of quotation-marks – it’s just cruising for a bruising.
