ЁЯУв Too many exams? DonтАЩt know which one suits you best? Book Your Free Expert ЁЯСЙ call Now!


    Question

    Which command safely iterates over filenames that may

    contain spaces and newlines in a shell script?
    A for f in $(ls); do ... Correct Answer Incorrect Answer
    B for f in *; do ... Correct Answer Incorrect Answer
    C ls | while read f; do ... Correct Answer Incorrect Answer
    D for f in $(find . -name '*'); do ... Correct Answer Incorrect Answer
    E for f in \ls`; do ... Correct Answer Incorrect Answer

    Solution

    for f in expands to filenames preserving spaces;lsand command substitution break on whitespace/newlines. For arbitrary names including newlines,find -print0withwhile IFS= read -r -d ''is safest but among options,for f in ` is correct.

    Practice Next
    More Shell Scripting Questions
    ask-question