Search code examples
bashawksedposix

One-liner POSIX command to lowercase string in bash


Problem

I have this comand:

sed $((SS - default_scripts))!d customScripts.txt

and it gives me Foo Bar.

I want to convert this to lowercase.

Attempt

When I tried using the | awk '{print tolower($0)}' command on it it returned nothing:

$($(sed $((SS - default_scripts))!d customScripts.txt) | awk '{print tolower($0)}')

Final

Please enlighten me on my typo, or recommend me another POSIX way of converting a whole string to lowercase in a compact manner. Thank you!


Solution

  • The pipe to awk should be inside the same command substitution as sed, so that it processes the output of sed.

    $(sed $((SS - default_scripts))!d customScripts.txt | awk '{print tolower($0)}')
    

    You don't need another command substitution around both of them.