Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search. The loop will run as long as! If you prefer, you can use until instead of while and remove the negation! Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Collectives on Stack Overflow. Learn more. Bash- How to check if file is empty in a loop Ask Question. Asked 4 years, 2 months ago. Active 4 years, 2 months ago. Viewed 7k times. The script should be like: while read line do if file is empty then; AIX 5.
I have a KSH script which does the following action cp a. How to empty a file already created. What is the command to empty an already existing file. Hi, I need your help. How can I create an empty filename with a specific size, in hp-ux? Regards, Mizi 2 Replies. RedHat Commands. OpenSolaris Commands. Linux Commands. SunOS Commands. FreeBSD Commands. Full Man Repository.
Advanced Search. Contact Us. Forum Rules. Mark Forums Read. Thread Tools. View Public Profile for lesstjm. Find all posts by lesstjm. Thus, you get "empty.
PS: If you want to check an actual diff call, just check the return value: if diff foo. Test can be negated: if [! Beware of the trailing new-line characters. Add a comment. Active Oldest Votes. Check your spelling of empty , but then also try this:! Improve this answer. The shell can help with misspellings. Using the tool shellcheck can find spelling errors just fine. Surely this will fail if the file does not exist either?
This is supposed to be a check if the file is empty only. You can also set -u — Jon McClung. What is the -e argument passed here in shebang? Show 5 more comments. The latter is bashism, which should be used only for incompatible bash checks e. Debian system scripts , you'll appreciate this habit yourself :.
Surya Surya 9, 3 3 gold badges 53 53 silver badges 36 36 bronze badges. Noam Manos Noam Manos This is the only good answer and should be the accepted one.
0コメント