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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:25:26+00:00 2026-05-30T01:25:26+00:00

I have a script that checks if a file exists or not using the

  • 0

I have a script that checks if a file exists or not using the ls command. If there is not a file I ask the user if he would like to continue with the script.

What I am finding is that the read command excepts input from the terminal instead of the keyboard?

Here is my script:

function isfileThere(){
  output=$(ls ${1}  2>&1 >/dev/null)
  case $output in
    *"No such file or directory"*) 
      echo "DS not found: $output";
      option_exitprog; $output >> DSNotFound.txt ;;
    *) echo "DS found: $output";;
  esac
}

function option_exitprog(){
  while :
    do
    echo -n "Would you like to continue (y/n)?"
    read Answer
    #read -n1 -p "Would you like to continue (y/n)?"   Answer                                                                                                                                                                                                                 

    if [ ! -z "$Answer" ] ; then
        if [ "$Answer" == "y" ] ; then
            echo "Exiting script. Goodbye"
            exit 1
        elif [ "$Answer" == "n" ] ; then
            echo "Continue With Program"
            break
        else
            echo "We only accept (y/n)"
        fi
    else
        echo "You have entered a null string. We only accept (y/n)"
    fi
  done
}

function get_TotalEventEntries(){

cat<<EOF                                                                                                                                                                                                                                                                 

####################################                                                                                                                                                                                                                                      
#                                  #                                                                                                                                                                                                                                      
#                                  #                                                                                                                                                                                                                                      
#        get Total Entries         #                                                                                                                                                                                                                                      
#                                  #                                                                                                                                                                                                                                      
#                                  #                                                                                                                                                                                                                                      
####################################                                                                                                                                                                                                                                      

EOF                                                                                                                                                                                                                                                                           

  while read LINE
    do
    let total_DSNumber=total_DSNumber+1

    #Check if files exist                                                                                                                                                                                                                                                   
    isfileThere ${FileDir}/*${LINE}*/*.root*

    #print to file                                                                                                                                                                                                                                                          
    #printf "${LINE}="  >> ${Filename}                                                                                                                                                                                                                                      
    #getEntries ${LINE} >> ${Filename}                                                                                                                                                                                                                                      
  done < ${DSWildCardFile}

  echo "Finished running over $total_DSNumber file(s)"
}

get_TotalEventEntries
  • 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-05-30T01:25:28+00:00Added an answer on May 30, 2026 at 1:25 am

    The problem is at this line: done < ${DSWildCardFile}. You cannot read lines from this file and read user at the same time with read and simple redirection . To fix it, use more complex redirection and a new file descriptor:

    while read -u 3 LINE
    do
      ...
    done 3< ${DSWildCardFile}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that checks responses from HTTP servers using the PEAR HTTP
I have a script that checks something on my PC every 5 minutes and
I have a script (or more accurately WILL have a script) that checks a
Ok, I have a validation script that checks everything on the form - but
I have a python script that analyzes a set of error messages and checks
I have a little Perl script (On Windows) that checks some files for me
I have an script that will show some compress options to the user (gzip,
I have CMS with a script that is executed for each file that is
I have a bash script that checks some log files created by a cron
I have a script that checks a website ($host) for an string of characters

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.