0

I know to get an input with a shell script you can do

echo "text"
read $VAR

or to get it at runtime

#! /bin/sh

if [ "$1" ]
then
  #do stuff
else
  echo "No input"
fi

But what if I want to get the entire string after I run it, including spaces? I could use quotation marks, but is there any way around this, so I can do: ./script.sh This is a sentence

1
  • 1
    don't echo text; read, use read -ptext var! Commented Nov 22, 2011 at 1:09

2 Answers 2

1

Use

#!/bin/sh

if [ $# -gt 0 ] ; then
    echo "$*"
else
    echo "No input"
fi

But first, think about what you're doing and just pass a single quoted parameter.

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

1 Comment

It sort-of works, provided you only have a single space between words and no other funny characters. I'll repeat @Sorpigal's advice: think about what you're doing and just pass a single quoted parameter.
0
./script.sh "This is a sentence"

another way is

./script.sh This\ is\ a\ sentence

1 Comment

I said, "I could use quotation marks, but is there any way around this".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.