简体   繁体   中英

Linux shell script: echo only a char, didnt handle spaces

I need a command in shell script, which write a string char by char

A found 2 versions which could work:

1 with using cut

And an another, using this:

echo -n ${line:$j-1:1}

Where j is a variable of a for loop which goin true the length of the string So this will write the string char by char, but didnt handle spaces (" ") (i guess it didnt write null chars, but i need them)

Someone can help?

您需要引用扩展名,以便在调用echo之前外壳不会删除空格:

echo -n "${line:$j-1:1}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM