简体   繁体   中英

How to pass an integer as an argument in Shell function and retrieve it

I have a small function like this -

#! /bin/sh
function hey() {
    a=$1
    echo $a
}

x=2
hey x

As per my understanding it should print 2 but it is printing x . How to resolve it?

Running you code in my bash (not sh) , it also prints x. But if i change the last line to

hey $x 

then it prints 2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM