The first arg pass on the terminal is $1, I also saw that the same was done for the first arg of a function. How do I differentiate between the two (when does, $1 refers to first arg from terminal and func
Hi there, very good question! The file argument $1 will not be available inside your function. So if you want to pass your $1 argument to your function you need to add it after the name of the function when calling it. Here is an example script to test with: ``` #!/bin/bash echo "Argument " ${1} function test(){ echo "Function Argument: " ${1} } test Fun ```
@@bobbyiliev_ assuming you do, `bash filename.sh Bobby` the output will be `Argument Bobby` `Function argument Fun` But `${1}` was used for both which made me confused a little. Thanks for the clarification
The first arg pass on the terminal is $1, I also saw that the same was done for the first arg of a function. How do I differentiate between the two (when does, $1 refers to first arg from terminal and func
Hi there, very good question!
The file argument $1 will not be available inside your function. So if you want to pass your $1 argument to your function you need to add it after the name of the function when calling it.
Here is an example script to test with:
```
#!/bin/bash
echo "Argument " ${1}
function test(){
echo "Function Argument: " ${1}
}
test Fun
```
@@bobbyiliev_ assuming you do, `bash filename.sh Bobby` the output will be `Argument Bobby`
`Function argument Fun`
But `${1}` was used for both which made me confused a little. Thanks for the clarification
@@michaelotu9723 Hi there! Yep exactly, you got it!
Thanks for the great question!