LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   function and parameter (https://www.linuxquestions.org/questions/linux-newbie-8/function-and-parameter-4175633039/)

DennyY 06-30-2018 11:51 PM

function and parameter
 
Hi,

Can someone tell me what's wrong with my script?

Quote:

#!/bin/bash

function hello
{
echo "Hi, my name is $1"
echo $(date)
}

hello $1
I ended up with this:

Quote:

Hi, my name is
Sat Jun 30 21:47:26 PDT 2018

Thank you,
Denny

DennyY 06-30-2018 11:53 PM

function and parameter
 
Sorry, I did find out what I missed.

Thank you all,
Denny

scasey 07-01-2018 12:47 AM

Would you share it with us, please?

AwesomeMachine 07-01-2018 04:08 AM

He probably ran the command without the name parameter, $1.

DennyY 07-02-2018 09:20 AM

function and parameter
 
Yes, you were correct. :redface:

-Denny



Quote:

Originally Posted by AwesomeMachine (Post 5874135)
He probably ran the command without the name parameter, $1.


scasey 07-02-2018 12:34 PM

Quote:

Originally Posted by AwesomeMachine (Post 5874135)
He probably ran the command without the name parameter, $1.

That’s what I presumed, too...but asking a question and then saying “I got it” without sharing the solution is counter to the spirit of LQ. Just wanted to make that point to the OP and other newbies.


All times are GMT -5. The time now is 07:07 AM.