0

I'm trying to make it so my bash shellcode can take multiple files as arguments. How would I do this?

atm this shellcode checks if only one files exsist and it checks every $2 seconds...

How would I make it take more files as arguments?

#!/bin/bash while [ ! -e $1 ] do sleep $2 if [ -e $1 ] then echo "$1 was created!" fi done 
1
  • 1
    How would you make the find command loop until the file is created? Commented Sep 6, 2019 at 2:35

1 Answer 1

1

Put the sleep time first, then loop over the remaining arguments.

time=$1 shift # Remove time from argument list for file in "$@" do while [ ! -e "$file" ] do sleep "$time" done echo "$file was created!" done 

You also don't need to test for the file's existence twice. When the loop ends, you know the file has been created.

If you want to put the time last, you can loop over the argument indexes, using indirect variables.

time=${!#} # last argument for ((i = 1; i < $#; i++)) do file=${!i} while [ ! -e "$file" ] do sleep "$time" done echo "$file was created!" done 
Sign up to request clarification or add additional context in comments.

2 Comments

Yeah I was thinking of this aswell, but what if I would want the timer at the end?
Change what you want

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.