I'm trying to use an alias in a shell script I'm writing, but it is not working.
The alias:
alias ts="awk '{ print strftime(\"[%Y-%m-%d %H:%M:%S]\"), \$0 }'"
When I run the script, I get the following error:
./copyTask.sh: ts: not found
Sooping around on the internet, it seems that I need to enable the expand_aliases
shell option, but I don't have shopt
installed... Is there any way I can enable alias expansion without using shopt
or creating another rootfs image?
I'm using the ash
shell. And awk
is BusyBox v1.25.0 awk
.
NOTE: The alias is an easy way to prepend a timestamp to a commmand:
$ echo "foo" | ts
[2005-06-23 11:52:32] foo
EDIT: as some people are having trouble understanding what I mean, this answer has an example.
expand_alias
is set... – Greenshankshopt
, your shell isn't bash. That happens, in practice, as if code is called with/bin/sh
. – Kirbyprintf %()T
support for timestamp formatting internal to the shell itself. – Kirbysh
binary is either a symlink to, or has the same inode number as -- and thus is a hardlink to -- the busybox executable; if it is busybox ash, I might change the title to "Using aliases in a script with busybox sh"). – Kirby