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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:47:15+00:00 2026-06-08T14:47:15+00:00

I am writing a shell script where parameter will be a path to a

  • 0

I am writing a shell script where parameter will be a path to a location. I am using readlink -f command to get the absolute path of the path send by user. Suppose if the path send by the user has spaces like,

    /home/stack over flow/location

I am excepting the user to send with quotes like

    "/home/stack over flow/location"

I have 2 issues here,

1) Even though if the path is passed with quotes, when I iterate over $@, quotes are suppressed and get path without quotes.

2) I did a work around to check if the parameter contain spaces and I add explicitly like

    if [[ $1 = *\ * ]] ; then
           temp=\"$1\"
    fi

where I added quotes ” explicitly, but the problem now I am facing is even though I added variable with spaces now readlink is not working.
When I do

    full_path=`readlink -f ${temp}`

Its saying
usage: readlink [-n] [-f] symlink

If I execute it as a normal unix command in shell like

       readlink -f "/home/stack over flow/location"

which is working and I am getting full path. Why even I append the spaces readlink is not working in shell script? Please help me out with this.

  • 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-08T14:47:24+00:00Added an answer on June 8, 2026 at 2:47 pm

    Well it makes sense that you get the path without quotes in the script parameters: the quotes are meant for the shell processing the call of your script, not for the script itself.
    I assume you call the command like this:

    ./test "/home/stack over flow/location"
    

    where ‘test’ is the script you implement. The quotes around the path make sure the shell that executes this command treats the path as one single argument, not as three separate strings as it would do without the quotes. But the quotes are not treated as part of the parameter itself. So when the parameter is handed over to your script you get one single parameter holding the whole path, not a parameter holding a modified string based on the path: the string with padded quotes.

    You can use that paramter without problems. Just put quotes around it again:

    readlink -f "$@"
    

    will protect the blanks contained in the specified path, just as in the original call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Shell Script where user will pass the path to JAVA_HOME
I'm writing a shell script which will store the output of a command in
I am writing a shell script that will perform 2 tasks. One task will
Im writing a shell script to use the scp command (ssh) to transfer a
I am writing a shell script on Ubuntu and use the sed command to
I'm writing a shell script. A variable will have a url that will look
I'm writing a shell script that needs to cd to some location. Is there
I'm writing a shell script which will rsync files from remote machines, some linux,
I'm writing a shell script to automatically add a new user and update their
I'm writing a shell script to edit Change-Set attributes of aegis. The command I'm

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.