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 186719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:41:46+00:00 2026-05-11T15:41:46+00:00

I did some havoc on my computer, when I played with the commands suggested

  • 0

I did some havoc on my computer, when I played with the commands suggested by vezult [1]. I expected the one-liner to ask file-names to be removed. However, it immediately removed my files in a folder:

> find ./ -type f | while read x; do rm '$x'; done 

I expected it to wait for my typing of stdin:s [2]. I cannot understand its action. How does the read command work, and where do you use it?

  • 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. 2026-05-11T15:41:47+00:00Added an answer on May 11, 2026 at 3:41 pm

    Charlie Martin gives you a good dissection and explanation of what went wrong with your specific example, but doesn’t address the general question of:

    When should you use the read command?

    The answer to that is – when you want to read successive lines from some file (quite possibly the standard output of some previous sequence of commands in a pipeline), possibly splitting the lines into several separate variables. The splitting is done using the current value of ‘$IFS‘, which normally means on blanks and tabs (newlines don’t count in this context; they separate lines). If there are multiple variables in the read command, then the first word goes into the first variable, the second into the second, …, and the residue of the line into the last variable. If there’s only one variable, the whole line goes into that variable.

    There are many uses. This is one of the simpler scripts I have that uses the split option:

    #!/bin/ksh # #   @(#)$Id: mkdbs.sh,v 1.4 2008/10/12 02:41:42 jleffler Exp $ # #   Create basic set of databases  MKDUAL=$HOME/bin/mkdual.sql ELEMENTS=$HOME/src/sqltools/SQL/elements.sql  cat <<! | mode_ansi with log mode ansi logged with buffered log unlogged stores with buffered log !  while read dbs logging do     if [ '$dbs' = 'unlogged' ]     then bw=''; cw=''     else bw='-ebegin'; cw='-ecommit'     fi     sqlcmd -xe 'create database $dbs $logging' \             $bw -e 'grant resource to public' -f $MKDUAL -f $ELEMENTS $cw done 

    The cat command with a here-document has its output sent to a pipe, so the output goes into the while read dbs logging loop. The first word goes into $dbs and is the name of the (Informix) database I want to create. The remainder of the line is placed into $logging. The body of the loop deals with unlogged databases (where begin and commit do not work), then run a program sqlcmd (completely separate from the Microsoft new-comer of the same name; it’s been around since about 1990) to create a database and populate it with some standard tables and data – a simulation of the Oracle ‘dual‘ table, and a set of tables related to the ‘table of elements’.

    Other scripts that use the read command are bigger (by far), but generally read lines containing one or more file names and some other attributes of relevance, and then apply an appropriate transform to the files using the attributes.

    Osiris JL: file * | grep 'sh.*script' | sed 's/:.*//' | xargs wgrep read esqlcver:read version letter jlss:    while read directory jlss:                read x || exit jlss:            read x || exit jlss:    while read file type link owner group perms jlss:        read x || exit jlss:    while read file type link owner group perms kb: while read size name mkbod:    while read directory mkbod:while read dist comp mkdbs:while read dbs logging mkmsd:while read msdfile master mknmd:while read gfile sfile version notes publictimestamp:while read name type title publictimestamp:while read name type title Osiris JL: 

    ‘Osiris JL: ‘ is my command line prompt; I ran this in my ‘bin’ directory. ‘wgrep‘ is a variant of grep that only matches entire words (to avoid words like ‘already’). This gives some indication of how I’ve used it.

    The ‘read x || exit‘ lines are for an interactive script that reads a response from standard input, but exits if the command gets EOF (for example, if standard input comes from /dev/null).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I did some work on a project on one machine, then pushed to github
I did some reading on the API for File IO and read the following
I did some timing tests and also read some articles like this one (last
I did some i/o function like load yaml configuration file and callback function will
I did some tests with memory_get_usage and memory_get_peak_usage. One of my scripts returns 1.3mb
Did some searches here & on the 'net and haven't found a good answer
Did some googling and couldn't find a clear answer on this. My assumption is
I did some research and found that the only way to vertically center a
I did some all day learning and I figured out how to add rows
Why did some processor manifacturers decide to use Little endian Big endian Middle endian

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.