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

  • Home
  • SEARCH
  • 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 6026713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:29:08+00:00 2026-05-23T04:29:08+00:00

I have a script that has a string in a file name like so:

  • 0

I have a script that has a string in a file name like so:

filename_with_spaces="a file with spaces"
echo test > "$filename_with_spaces"
test_expect_success "test1: filename with spaces" "
  run cat \"$filename_with_spaces\"
  run grep test \"$filename_with_spaces\"
"

test_expect_success is defined as:

test_expect_success () {
  echo "expecting success: $1"
  eval "$2"
}

and run is defined as:

#!/bin/zsh
# make nice filename removing special characters, replace space with _
filename=`echo $@ | tr ' ' _ | tr -cd 'a-zA-Z0-9_.'`.run
echo "#!/bin/zsh" > $filename
print "$@" >> $filename
chmod +x $filename
./$filename

But when I run the toplevel script test_expect_success… I get cat_a_file_with_spaces.run with:

#!/bin/zsh
cat a file with spaces

The problem is the quotes around a file with spaces in cat_a_file_with_spaces.run is missing. How do you get Z shell to keep the correct quoting?

Thanks

  • 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-23T04:29:09+00:00Added an answer on May 23, 2026 at 4:29 am

    Try

    run cat ${(q)filename_with_spaces}
    

    . It is what (q) modifier was written for. Same for run script:

    echo -E ${(q)@} >> $filename
    

    . And it is not bash, you don’t need to put quotes around variables: unless you specify some option (don’t remember which exactly)

    command $var
    

    always passes exactly one argument to command no matter what is in $var. To ensure that some zsh option will not alter the behavior, put

    emulate -L zsh
    

    at the top of every script.

    Note that initial variant (run cat \"$filename_with_spaces\") is not a correct quoting: filename may contain any character except NULL and / used for separating directories. ${(q)} takes care about it.

    Update: I would have written test_expect_success function in the following fashion:

    function test_expect_success()
    {
        emulate -L zsh
        echo "Expecting success: $1" ; shift
        $@
    }
    

    Usage:

    test_expect_success "Message" run cat $filename_with_spaces
    
    • 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 takes a table name and generates a control file
I have a python script that has to launch a shell command for every
I have a script that needs to run after tomcat has finished starting up
I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example),
I have a script that works fine on my test server (using IIS6). The
I have the current script included below that goes into a file with extension
I have a script that retrieves objects from a remote server through an Ajax
I have a script that checks responses from HTTP servers using the PEAR HTTP
I have a script that renders graphs in gnuplot. The graphs all end up
I have a script that successfully encrypts a credit card. I need it to

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.