0

I understand that variables are global unless otherwise stated local, but for some reason, (and it's probably my own stupidity) it's not working. I have searched around to no avail.

#!/bin/bash

function a {
    echo $1
}

echo $1
a

Say you pass the word car to it. It should display it twice. It doesn't. Only once.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Watael
0

hi,

that's because $1 is kind of local: functions have their own positionnal parameters; and as you don't pass args to the function it echoes an empty line.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.