Execute multiple commands after [ test

Elliott B

How can I use a simple one-line test and execute multiple commands if the test is true? The following does not work:

for f in $source_dir/*.mov
do
   [ ! -f "$f" ] && echo "No files in source directory. Exiting."; break || continue
   # a bunch of commands
done

I got it to work using the below code, but I feel like there should be as simpler way.

for f in $source_dir/*.mov
do
   if [ ! -f "$f" ]; then
      echo "No files in source directory.  Exiting."
      break
   else
      # a bunch of commands
   fi
done
rici

Use {:

[[ ! -f "$f" ]] && { this; that; break; } || { the_other; ...; }

Whether that's "simpler" or not is a question of aesthetics.

Using [[ instead of [ is optional. But it's usually better.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Execute multiple commands after [ test

From Dev

execute multiple commands after ssh

From Dev

How to execute multiple commands after opening a new terminal tab

From Dev

How to execute multiple commands after opening a new terminal tab

From Dev

Delphi - CreateProcess - Execute multiple commands

From Dev

Running a .sh to execute multiple commands

From Dev

Running multiple commands for npm test

From Dev

Laravel 5 Commands - Execute one after other

From Dev

execute commands as user after Vagrant provisioning

From Dev

bash script execute commands after ssh

From Dev

Laravel 5 Commands - Execute one after other

From Dev

Is there a way to execute commands after file changed?

From Dev

pass multiple commands for cmd to execute as one block

From Java

Execute combine multiple Linux commands in one line

From Dev

Execute multiple sage commands from php script

From Dev

How to execute multiple CLI commands in a python script?

From Dev

Execute multiple SQL commands at once on R

From Dev

Have puppet conditionally execute multiple commands

From Dev

execute multiple commands in cmd using java

From Dev

Gradle -- execute multiple commands from task

From Dev

execute multiple commands on console through unix shell

From Dev

How to execute multiple commands remotely on few servers?

From Dev

How to execute multiple commands in Bash, some in the background

From Dev

Execute multiple commands over ssh without reconnecting

From Dev

Execute multiple commands with 1 line in Windows commandline?

From Dev

How to execute multiple CLI commands in a python script?

From Dev

execute multiple commands in cmd using java

From Dev

Execute multiple ssh commands with different switch

From Dev

Execute multiple commands in a terminal window from bash

Related Related

  1. 1

    Execute multiple commands after [ test

  2. 2

    execute multiple commands after ssh

  3. 3

    How to execute multiple commands after opening a new terminal tab

  4. 4

    How to execute multiple commands after opening a new terminal tab

  5. 5

    Delphi - CreateProcess - Execute multiple commands

  6. 6

    Running a .sh to execute multiple commands

  7. 7

    Running multiple commands for npm test

  8. 8

    Laravel 5 Commands - Execute one after other

  9. 9

    execute commands as user after Vagrant provisioning

  10. 10

    bash script execute commands after ssh

  11. 11

    Laravel 5 Commands - Execute one after other

  12. 12

    Is there a way to execute commands after file changed?

  13. 13

    pass multiple commands for cmd to execute as one block

  14. 14

    Execute combine multiple Linux commands in one line

  15. 15

    Execute multiple sage commands from php script

  16. 16

    How to execute multiple CLI commands in a python script?

  17. 17

    Execute multiple SQL commands at once on R

  18. 18

    Have puppet conditionally execute multiple commands

  19. 19

    execute multiple commands in cmd using java

  20. 20

    Gradle -- execute multiple commands from task

  21. 21

    execute multiple commands on console through unix shell

  22. 22

    How to execute multiple commands remotely on few servers?

  23. 23

    How to execute multiple commands in Bash, some in the background

  24. 24

    Execute multiple commands over ssh without reconnecting

  25. 25

    Execute multiple commands with 1 line in Windows commandline?

  26. 26

    How to execute multiple CLI commands in a python script?

  27. 27

    execute multiple commands in cmd using java

  28. 28

    Execute multiple ssh commands with different switch

  29. 29

    Execute multiple commands in a terminal window from bash

HotTag

Archive