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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.