2

I'm using the 'at' command in order to create 3 directories, just a dumb bash script:

#!/bin/bash
for i in {1..3}
do
mkdir dir$i
done

Everything is ok if I execute that script directly on terminal, but when I use 'at' command as follows:

at -f g.sh 18:06

It only creates one directory named dir{1..3}, taking interval not as an interval but as a list with one element {1..3}. According to this I think my mistake is using bash script due to at executes commands using /bin/sh but I'm not sure. Please tell me if I'm right and I would appreciate some alternative to my code since even it is useless I'm curious to know what's wrong with at and bash.

hlovdal
  • 23,353
  • 10
  • 78
  • 148
Hellzzar
  • 165
  • 8
  • 1
    Yes, `at` executes the commands from file `g.sh` at the given time. It will read each commands from this file. It's like doing `sh g.sh`. Instead try `at 18:06 <<< "/full/path/to/g.sh"`. – gniourf_gniourf Mar 05 '15 at 18:02

1 Answers1

2

The #! line only affects what happens when you run a script as a program (e.g. using it as a command in the shell). When you use at, it's not being run as a program, it's simply used as the standard input to /bin/sh, so the shebang has no effect.

You could do:

echo './g.sh' | at 18:06
Barmar
  • 596,455
  • 48
  • 393
  • 495