0

I have a script with a simple globbing pattern to create multiple files and it works just as I want it to. The problem arises when I use the at command to schedule the running of the script. Somehow, the script creates only one file instead of the many files it should create.

This is the code below:

#!/bin/bash

mkdir folder1

touch folder1/file{1..100}.txt

This somehow creates only file{1..100}.txt in the folder1 directory instead of a hundred files.

Output when I schedule the script to run at any given time:

  stevis@stevis:~/Desktop/Linux/bash/scheduling$ ls folder1/
  file{1..100}.txt
  
tripleee
  • 175,061
  • 34
  • 275
  • 318
Sstevis
  • 1
  • 1
  • 1
    Looks like it is being executed with `/bin/sh`, not `bash`. How are you scheduling your script with `at`? – knittl Oct 13 '22 at 15:22
  • 1
    `at` runs `sh`, not `bash`. You even get a warning when you run it. – tripleee Oct 13 '22 at 15:22
  • 2
    Mind, if you tell `at` to invoke your script _as an executable_, the shebang will be honored and it'll run with bash anyhow; but the details of how you're doing that invocation matter. If you don't show us exactly how you run `at`, this isn't answerable. – Charles Duffy Oct 13 '22 at 15:24
  • 3
    (btw, how/why is this tagged python?) – Charles Duffy Oct 13 '22 at 15:25
  • MAybe problema can showup due to en error in the folder creation. Make shure you cleanup previous directory: `rm -rf folder1`. I also suggest `mkdir -p folder1` – jonasmike Oct 13 '22 at 16:51
  • The problem was that /bin/sh file was linked to dash. Running this command confirmed it; file -h /bin/sh. So i changed it to bash using this command sudo ln -sf bash /bin/sh and it worked. Thank you all for your prompt response. – Sstevis Oct 13 '22 at 20:01

0 Answers0