0

I want to write a shell script myscript. The user will type a folder to get it to work:

~$: myscript /myfolder1/random folder/fb/picture set/...

As you can see depends on the folder there are unknown number of spaces in the input.

I want myscript to be able to interpret the whole input as one input. What can i do to achieve this?

I can use read command to capture the input, but it only expects the input in the next line after the user types

myscript+enter.

Which is not what i want.

2
  • What output are you expecting? Can you show your script? Each space delimited argument will become $1 $2 $3 ... in the script. Commented Feb 8, 2014 at 5:35
  • Use quotes " ' or whitespace escaping. ./myscript "/myfolder1/random folder/fb/picture set/" Commented Feb 8, 2014 at 5:35

3 Answers 3

1

You can't, since your script can't know how much whitespace there is, which whitespace characters are being used, or whether certain arguments are supposed to be flags or fragments of paths. Your users will have to correctly quote arguments to the script.

Sign up to request clarification or add additional context in comments.

Comments

0
myscript "/myfolder1/random folder/fb/picture set/..."

will make one argument.

Comments

0

Hard to tell exactly what you are trying to do without more context, but you can use $@ to get all the arguments together.

#!/bin/bash
echo zzz "$@" zzz

Then if you run it:

myscript a b c

You get:

zzz a b c zzz

1 Comment

Although you really should be using "$@" instead so that you don't break your arguments up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.