You are not logged in.
... or just something I've never noticed before
$ cat weird.sh
#!/usr/bin/bash
testfunc() {
echo "test inside function $1"
}
echo "test outside function $1"
testfunc$ ./weird.sh arg1
test outside function arg1
test inside function $ bash --version
GNU bash, version 4.3.26(1)-release (x86_64-unknown-linux-gnu)I was expecting $1 to be returned from the function too (and it does work if I add $1 as a variable - i,e. ARG=$1)
Last edited by oliver (2014-09-29 21:21:29)
Offline
Works as it always has. Function invocation resets the positional paramters to the passed arguments. So, since you didn't pass any arguments to the function, $1 is empty inside the function block.
See 'set' in the 'SHELL BUILTIN COMMANDS' section in the bash manual page.
Last edited by aiBo (2014-09-29 21:12:44)
Offline
just something I've never noticed before
This.
As aiBo explained, you're not passing anything to the function, so $1 is not set inside it.
To further elaborate on this, what would you expect the output of the following to be?:
$ cat weird.sh
#!/usr/bin/bash
testfunc() {
echo "test inside function $1"
}
echo "test outside function $1"
testfunc abc
$ ./weird.sh arg1Last edited by WorMzy (2014-09-29 21:22:59)
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Works as it always has. Function invocation resets the positional paramters to the passed arguments. So, since you didn't pass any arguments to the function, $1 is empty inside the function block.
See 'set' in the 'SHELL BUILTIN COMMANDS' section in the bash manual page.
Thanks! Makes perfect sense now
Offline
To further elaborate on this, what would you expect the output of the following to be?:
yeah - I see what you mean and I appreciate the further elaboration
Offline
I have been told this code show the vunerability:
$ env x='() { :;}; echo vulnerable' bash -c "echo this is a test"Offline