I have a script which gets called with two parameters:
./script.sh a b
I'm currently reading them through $1 and $2 (such as cd $1
). My problem is that the output needs to be the same for when the script gets called with quoted parameters:
./script.sh "a b"
which, if I understand it correctly, passes both parameters into the $1
variable.
Is there a simple and clean way to do this or do I need to check the first parameter for spaces, split it into an array, pass parts of the array into two separate variables and then use them throughout the script?
if [ $# < 2 ] ; then set -- ${1% *} ${1#* } ; fi
of course.echo -e "\n$1"
It still outputs "a b", whereas I need for it to be "a".#!/bin/bash if [ 0 < 2 ] ; then set -- ${1% *} ${1#* } ; fi echo -e "\n$1"
outputsa