I need to create file with name is the result of the command in Solaris

I need to create only one file with name is the result of the command ls -l | head -2.
I can’t use environment variables. The filename must contain newline symbols.

I’ve tried to use touch 'ls -l | head -2', but it hasn’t worked.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

You can use the output of that command directly as the input of touch:

touch "$(ls -l | head -2)"

The quotes are important, as there are bound to be spaces and a newline in the output of the ls -l | head -2 part.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply