Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:26:45+00:00 2026-06-04T21:26:45+00:00

Following is the shell script to read all the DSF present in the box.

  • 0

Following is the shell script to read all the DSF present in the box. But since the line is having spaces, it is displaying them in different lines.
For those of you who dont understand ioscan -m dsf, replace it by ls -ltr, then the output is such that the permission and names are displayed in different line, but i want them in the same line.

#!/usr/bin/ksh

for a in `ioscan -m dsf`
do
 echo  $a
done
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:26:47+00:00Added an answer on June 4, 2026 at 9:26 pm

    The for loop is not designed to loop over lines. Instead it loops over words. Words are things separated by space. Lines are things separated by newline. More on that later.

    The idiomatic way to loop over lines is to use a while loop in combination with read:

    ioscan -m dsf | while read -r line
    do
      printf '%s\n' "$line"
    done
    

    Alternatively:

    while read -r line
    do
      printf '%s\n' "$line"
    done < <(ioscan -m dsf)
    

    Both work fine for most simple cases. The second variant is using a process substitution which might not be available in all shells.

    Both variants have advantages and disadvantages which mainly become apparent if you want to manipulate variables inside the loop.

    For more information see http://mywiki.wooledge.org/BashFAQ/024


    technical nitpick:

    words, or fields as they are called in bash, are things separated by space but also by tab and newlines. basically things separated by whitespace.

    the separator separating the fields is defined in the IFS variable (short for Internal Field Separator). Usually $IFS contains a space, a tab, and a newline.

    Often you will see the suggestion to loop over lines by changing the value of $IFS to only newline.

    # not recommended
    OLDIFS="$IFS"
    IFS=$'\n'
    for line in $(ioscan -m dsf)
    do
      printf '%s\n' "$line"
    done
    IFS="$OLDIFS"
    

    (the $'\n' is is called ANSI-C Quoting and might not be available in all shells)

    I do not recommend changing $IFS. Many commands rely on sane setting for $IFS. Changing $IFS will often cause an endless nightmare of obscure bug hunting.


    See also:

    • http://wiki.bash-hackers.org/syntax/ccmd/classic_for
    • http://wiki.bash-hackers.org/commands/builtin/read
    • http://mywiki.wooledge.org/IFS
    • http://mywiki.wooledge.org/SubShell
    • http://mywiki.wooledge.org/ProcessSubstitution
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found following piece of code written as a shell script to read from
I am using the following awk statement in my shell script. #!/bin/sh # read
Following the shell script that I am executing #!/bin/sh echo Enter [y/n] : read
I am wondering is there any way to execute following shell script, which waits
I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar
I came across this shell script for OSX and I don't understand the following:
I am trying to write a shell script to simulate the following problem: File
Say for example you had a shell script that utilises inotifywait in the following
I have the following shell script and want to change the filename db_backup.sql to
I have the following in a shell Perl script: my @LS = `ls -1t

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.