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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:42:02+00:00 2026-06-04T02:42:02+00:00

How do I pass a blank line from a file as an argument to

  • 0

How do I pass a blank line from a file as an argument to a bash script within another script?

Here are the details. script bar reads in lines from inputfile, stores them in an array, and passes the array elements as options and/or arguments to script foo. inputfile looks something like this:

-l file1
dirA

-c
-lc file2
file2

-cd file3
file4

(etc.) Here is what happens. Script bar reads the file line by line and creates the array properly, including two empty elements for the blank lines. (I have checked this by echoing each array element.) But when bar traverses the array in a loop and passes each element to script foo, the two empty elements are skipped. So the cases where script foo should be invoked with zero arguments and zero options simply do not happen. All the other runs of script foo run as expected.

I thought perhaps the problem was that because the input file had nothing except a newline character, perhaps those elements in the array were just null rather than containing an empty string. So I tried putting spaces in the input file “blank” lines to see if it would make any difference, but the result was the same.

What do I need to do so that bar properly calls foo with no argument and no options when the input file has a blank line, or at least, a line with just whitespace characters?

I hope the question is clear. Thanks for your help!

EDIT. Someone suggested I post the script, so here is the relevant portion:

# read in input lines from file, add to array
index=0
while read line 
do
tests[index]=$line
(( index++ ))
done < $@

# run tests
for stuff in ${tests[@]}
do  
foo ${stuff} > /dev/null 2>&1
    # capture and process the exit status of each foo run
done

I know this looks as though I haven’t set IFS. That’s because this is only a part of my script. I am quite sure that the issue is here somewhere; the array does get properly built with the two elements with blank lines, but those elements are skipped in the for ... in loop.

  • 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-04T02:42:03+00:00Added an answer on June 4, 2026 at 2:42 am

    If you add double quotes where needed, it should work. (I’m only guessing because you did not show how you iterate over the lines).

    #! /bin/bash
    switches=('-n a'
        '-e "b\nc"'
        ''
        x)
    for s in "${switches[@]}" ; do
        echo $s
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Everyone knows PHP hates blank lines at the beginning or end of a file
I pass in the following XML to XMLin : <root foo=bar foo2=bar2> <pizzas> <pizza>Pepperoni</pizza>
I am trying to pass parameters from Visual Studio using VB.net to a Crystal
I'm trying to pass this to a PHP script through AJAX: var answers={}; for
Is it possible to pass a delegate to a WCF remote object from the
I want to pass a few variables to another page. Currently I'm using response.redirect
I have this small script that sorts the content of a text file #
I am trying to pass a parameter from AJAX back to my JSP page.
In Java, I can pass an object straight in parameter public int foo (Bar
I am calling my makewindows function from a PHP file like so: echo <a

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.