0

the command in bash_profile

alias getTime1='date -d @1490170832 +"%F %H:%M:%S"'

alias getTime2='date -d @$1'

but in terminal it not work

donaldlin@ ~ $ getTime1

2017-03-22 16:20:32

donaldlin@ ~ $ getTime2 1490170832

date: the argument ‘1490170832’ lacks a leading '+'; when using an option to specify date(s), any non-option argument must be a format string beginning with '+' Try 'date --help' for more information.

I have tried "date -d @\$1","date -d @'$1'","date -d ${@$1}" and so on, but it still not work.

update: aliases can't take parameters. You need to create a function instead Thanks @chepner and @l0b0

donald
  • 15
  • 4
  • Hi, welcome to StackOverflow. Please don't write your problem in the form of photos. Instead please write down (with appropriate formatting) the question. Also read this for how to ask a question here- https://stackoverflow.com/help/mcve – Chem-man17 Mar 23 '17 at 08:27
  • thanks for your advices – donald Mar 23 '17 at 08:31

1 Answers1

0

aliases can't take parameters. You need to create a function instead.

l0b0
  • 55,365
  • 30
  • 138
  • 223
  • I don't agree with you. I have try "cat $1" use alias. It is OK. – donald Mar 23 '17 at 08:46
  • 2
    @donald: You probably defined your alias with double quotes, `alias foo="cat $1"`, which means `$1` expanded to an empty string and was discarded at the time of the definition. This means your alias is exactly the same as `alias foo=cat`. Aliases do *not* take arguments. – chepner Mar 23 '17 at 12:35
  • @chepner Oh, I see. Thank you very much. I try `alias foo1="cat $1,$2"` and `alias foo2="cat $2,$1`, and I get the answer. – donald Mar 24 '17 at 02:33