Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash script and command definition [duplicate]

Tags:

bash

Got a little bash script like so:

#!/bin/bash
TIME_CMD='/usr/bin/time -f "%E execution time"'

${TIME_CMD} ls

Only problem: doesn't work:

/usr/bin/time: cannot run execution: No such file or directory
Command exited with non-zero status 127
"0:00.00

What am I doing wrong?

like image 676
Wells Avatar asked Dec 29 '22 03:12

Wells


1 Answers

Try making it...

#!/bin/bash
TIME_CMD='/usr/bin/time -f "%E execution time"'

eval "$TIME_CMD ls"

This will utilize bash to re-parse the command string after it has been constructed, so that the quoted argument will be recognized properly.

like image 51
Amber Avatar answered Jan 19 '23 03:01

Amber