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 Java

Execute combine multiple Linux commands in one line

From Dev

Have puppet conditionally execute multiple commands

From Dev

execute commands as user after Vagrant provisioning

From Dev

Execute multiple sage commands from php script

From Dev

bash script execute commands after ssh

From Dev

execute multiple commands in cmd using java

From Dev

How to execute multiple CLI commands in a python script?

From Dev

How to execute multiple commands after opening a new terminal tab

From Dev

Laravel 5 Commands - Execute one after other

From Dev

pass multiple commands for cmd to execute as one block

From Dev

execute multiple commands on console through unix shell

From Dev

Gradle -- execute multiple commands from task

From Dev

Running multiple commands for npm test

From Dev

Execute multiple SQL commands at once on R

From Dev

Delphi - CreateProcess - Execute multiple commands

From Dev

How to execute multiple commands remotely on few servers?

From Dev

Execute multiple commands after [ test

From Dev

Running a .sh to execute multiple commands

From Dev

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

From Dev

execute multiple commands after ssh

From Dev

execute multiple commands in cmd using java

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

How to execute multiple commands after opening a new terminal tab

From Dev

Execute multiple commands in a terminal window from bash

From Dev

Execute multiple ssh commands with different switch

From Dev

Laravel 5 Commands - Execute one after other

From Dev

Is there a way to execute commands after file changed?

Related Related

  1. 1

    Execute combine multiple Linux commands in one line

  2. 2

    Have puppet conditionally execute multiple commands

  3. 3

    execute commands as user after Vagrant provisioning

  4. 4

    Execute multiple sage commands from php script

  5. 5

    bash script execute commands after ssh

  6. 6

    execute multiple commands in cmd using java

  7. 7

    How to execute multiple CLI commands in a python script?

  8. 8

    How to execute multiple commands after opening a new terminal tab

  9. 9

    Laravel 5 Commands - Execute one after other

  10. 10

    pass multiple commands for cmd to execute as one block

  11. 11

    execute multiple commands on console through unix shell

  12. 12

    Gradle -- execute multiple commands from task

  13. 13

    Running multiple commands for npm test

  14. 14

    Execute multiple SQL commands at once on R

  15. 15

    Delphi - CreateProcess - Execute multiple commands

  16. 16

    How to execute multiple commands remotely on few servers?

  17. 17

    Execute multiple commands after [ test

  18. 18

    Running a .sh to execute multiple commands

  19. 19

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

  20. 20

    execute multiple commands after ssh

  21. 21

    execute multiple commands in cmd using java

  22. 22

    Execute multiple commands over ssh without reconnecting

  23. 23

    Execute multiple commands with 1 line in Windows commandline?

  24. 24

    How to execute multiple CLI commands in a python script?

  25. 25

    How to execute multiple commands after opening a new terminal tab

  26. 26

    Execute multiple commands in a terminal window from bash

  27. 27

    Execute multiple ssh commands with different switch

  28. 28

    Laravel 5 Commands - Execute one after other

  29. 29

    Is there a way to execute commands after file changed?

HotTag

Archive