1

I have a problem trying to write the output of a shell command to a file.

This works

cssbeautify basket.css > file.css

This doesn't. basket.css has now no content

cssbeautify basket.css > basket.css

Is that a normal behavior? How to get around it?

Edit: Here is the command I'm using to beautify all the files in the folder. You might find it useful.

for f in *;
do cssbeautify $f > temp_file && mv temp_file $f;
done

2 Answers 2

4

You cannot use a file as "pattern" and redirect to it.

Use for example:

cssbeautify basket.css > temp_file && mv temp_file basket.css

It will create a temp_file and -in case the first command runs successfully- then will overwrite it to basket.css.

Sign up to request clarification or add additional context in comments.

Comments

2

cssbeautify reads from basket.css, beautifies it and writes to STDOUT.

By using > basked.css you instruct the shell to write the output to basked.css. Before that the file content is cleared. cssbeautify thus reads an empty file and outputs an empty file.

So yes this is the normal behavior. You could write to a temporary file and mv it afterwards.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.