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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:05:24+00:00 2026-06-07T10:05:24+00:00

I have a bash script which I would like to handle spaces. I know

  • 0

I have a bash script which I would like to handle spaces. I know there a ton of questions on here about this, but I was unable to resolve my problem.

According to what I’ve read, the following should work. The space in
../tool_profile/OS\ Firmware/updater is being escaped. In the script, the $2 variable is being enclosed in quotes when being assigned to DEST.

If I pass this path in to ls enclosed in quotes or with escaped spaces on the command line, it works.

example script command:

./make_initramfs.sh initramfs_root/ ../tool_profile/OS\ Firmware/updater/ initramfs

error from ls in script:

ls: cannot access ../tool_profile/OS Firmware/updater/: No such file or directory

make_initramfs.sh:

#!/bin/bash

if [ $# -ne 3 ]; then
        echo "Usage: `basename $0` <root> <dest> <archive_name>"
        exit 1
fi

ROOT=$1
DEST="$2"
NAME=$3

echo "[$DEST]"

# cd and hide output
cd $ROOT 2&>/dev/null

if [ $? -eq 1 ]; then
        echo "invalid root: $ROOT"
        exit 1
fi


ls "$2" # doesn't work
ls "$DEST" # doesn't work


# check for 'ls' errors
#if [ $? -eq 1 ]; then
#        echo "invalid dest: $DEST"
#        exit 1
#fi

#sudo find . | sudo cpio -H newc -o | gzip --best > "$DEST"/"$NAME"

Thank you for any clues to what I am doing wrong! ^_^

  • 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-07T10:05:25+00:00Added an answer on June 7, 2026 at 10:05 am

    Okay… so right as I submitted this I realized what I was doing wrong.

    I was passing two relative paths in and changing to the first one before verifying the second one. So once I changed directory, the second relative path was no longer valid. I will post an updated script once I get it finished.

    Edit: I finished my script. See below.
    Edit2: I updated this based on everyone’s comments. Thanks everyone!

    make_initramfs.sh:

    #!/bin/bash
    
    
    if (( $# != 2 )); then
        echo "Usage: `basename $0` <root> <dest>"
        exit 1
    fi
    
    root="$1"
    archive="${2##*/}"
    dest="$PWD/${2%/*}"
    
    # cd and hide errors
    cd "$root" &>/dev/null
    if (( $? != 0 )); then
        echo "invalid path: $root"
        exit 1
    fi
    
    if [ ! -d "$dest" ]; then
        echo "invalid path: $dest"
        exit 1
    fi
    
    if [ "$archive" = "" ]; then
        echo "no archive file specified"
        exit 1
    fi
    
    if [ `whoami` != root ]; then
        echo "please run this script as root or using sudo"
        exit 1
    fi
    
    find . | cpio -H newc -o | gzip --best > "$dest"/"$archive"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this bash script which pases a text file and I would like
I have a Bash shell script in which I would like to pause execution
I have a BASH script which runs other commands and I would like to
Currently I have a bash script which runs the find command, like so: find
I have a bash script, that I run like this via the command line:
I have a bash script which calls another bash script, like so: #!/bin/bash echo
I would like to reference a variable that I have in a bash script
I have a bash script which need to execute some php scripts and to
I have written a bash script which installs a number of packages, however for
I have a Makefile from which I want to call another external bash script

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.