Bash shell unwanted file expansion at the space character

Posted on 2006-04-17
Last Modified: 2008-02-26
I'm trying to process a bunch of subdirectories that have spaces in the name.
The following bash script is expanding $thisfile at the space, so the file command fails as it never gets the full path/filename
How can this be fixed.

  echo $thisfile
does not expand $thisfile


find . -print | while read thisfile
file $thisfile
Question by:sheepfarmer
    LVL 45

    Accepted Solution

    Hi sheepfarmer,

    Enclose the parameter in double quotes

    file "$thisfile"
    echo $thisfile
    does not expand $thisfile

    This would happen if you are executing the echo command in a different shell. Typically scripts are launched in sub-shell. Hence variables which have been in the script would not be visible on the main shell.


    Author Comment

    Thanks for the solution - embarrassingly simple :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now