Home>

I want to display a multi-line character string in bash, but it cannot be displayed.

String

overlay 61255492 5973732 52140436 11%/\ n/dev/vda1 61255492 5973732 52140436 11%/etc/hosts \ n

I want to put out this character string in this form.

overlay 61255492 5973732 52140436 11% /
/ dev/vda1 61255492 5973732 52140436 11%/etc/hosts
What I tried

For echo

overlay 61255492 5973732 52140436 11%/\ n/dev/vda1 61255492 5973732 52140436 11%/etc/hosts \ n

printf "% s" "${MOJI}"

overlay 61255492 5973732 52140436 11%/\ n/dev/vda1 61255492 5973732 52140436 11%/etc/hosts \ n

printf "${MOJI}"

* There is an error display
printf: `/': invalid format character
  • Answer # 1

    How about something like this?

    echo'abc \ ndef' | sed's/\\ n/\ n/g'

  • Answer # 2

    What I tried

    Write not only the result, but also the command you executed. "If this happens, this is what happened."

    If you want the backslash to be interpreted as an escape sequence such as a newline,echo -eIs used.

    echo -e'overlay 61255492 5973732 52140436 11%/\ n/dev/vda1 61255492 5973732 52140436 11%/etc/hosts \ n'

    printf: `/': invalid format character

    %%IsprintfIt is a special character in."% d"Have you ever seen it?

    printfso%%When you want to display%%Write.