Creating a command line in a shell using a script

How can I code a command / program in a Unix shell without writing a loop to a script or other application.

For example, I wrote a script that displays the value of a light sensor, but I'm still testing it right now, so I want it to run it in a loop, re-running the executable.

Perhaps I would also like to just run "ls" or "df" in a loop. I know that I can do this easily in a few lines of bash code, but the ability to enter commands in the terminal for any given set of commands will be just as useful to me.

+3
source share
4 answers

, script, , , ,

for NAME [in LIST ]; do COMMANDS; done

script, , , repeat, , , N , COMMANDS $1.

+5

, , . , . , , -, , for, - .

for $file in `find . -name *.wma`; do cp $file  ./new/location/ done;

.

+2

"watch", , , , .

, , watch ls watch ./my_script.sh. , , , -n, -d, .

Try:

ls :

watch -n 1 ls

my_script.sh 3 :

watch -n 3 -d ./my_script.sh

: http://linux.die.net/man/1/watch

+2

, , script, . bash, , , :

while sleep 5s
do
  ls photos
end
+1

Source: https://habr.com/ru/post/1754056/


All Articles