tags:

views:

54

answers:

5

Hi,

in a bash script I am implementing some functions, that take parameters

The problem is when the parameters instaed of being MONDAY is END OF THE WEEK

How can I pass this parameter to the function so the function

function week{
TIME=$1
}

takes a $TIME "END OF THE WEEK" and not just "END" ?

Thanks

A: 
function week {
  TIME="$1"
}
Paul R
+2  A: 

Enclose a variable in double quotes to prevent word splitting but interpolate the variable's value. Single quoted strings undergo even less processing.

function week {
    TIME="$1"
}

week 'END OF THE WEEK'
outis
+2  A: 

You can use:

TIME="$*"

to get all of the parameters strung together, as in:

#!/bin/bash
function week {
        TIME="$*"
        echo "${TIME}"
}
week end of the week

which produces (all four arguments used):

end of the week

If you want to preserve white space. you can pass it as a quoted string.

#!/bin/bash
function week {
        TIME="$*"
        echo "${TIME}"
}
week "end        of the week"

which produces (from a single argument):

end        of the week
paxdiablo
A: 
function week {
  TIME="$1"
}
muruga
A: 
function week {
  TIME="$1"
}

--syntax editing slowed me down ;)

Decado