Skip to main content

Questions tagged [control-flow]

Control flow refers to the order that computer code is executed in when a program or script is running. Examples include loops (code is repeated) and conditionals where one branch is run instead of another. Use this tag for questions about control flow in scripts or programs – not questions about terminal flow control.

7 votes
3 answers
912 views

With `#!/bin/sh`, what is the closest to `;;&` (`bash`'s fallthrough)?

Without ;;&, /bin/sh gives Syntax error: ")" unexpected (expecting ";;"). ;;& triggers shellcheck's ^-- SC2127 (error): To use cases with ;;&, specify #!/usr/bin/env ...
Swudu Susuwu's user avatar
1 vote
3 answers
350 views

How to tail continuously a log file that is being deleted and recreated?

I need to extract information from a log file that is deleted and recreated every time a program runs. After detecting that the file exists (again), I would like to tail it for a certain regexp. The ...
user2066480's user avatar
0 votes
1 answer
154 views

Is a newline equivalent to && in a bash script?

I'm very simply wondering if, in a bash script, a new line is functionally 100% equivalent to &&? e.g.: #!/bin/bash 7z x "${file}" mv "${file}" "${new_file}" ...
s.k's user avatar
  • 521
2 votes
4 answers
167 views

How to execute a command after the previous non-terminating command prints a certain string?

I want to execute commandA which prints the following: line1 line2 line3 started successfully line4 ... ... And when the line started successfully is printed I want to start another command (and ...
Marinos An's user avatar
5 votes
3 answers
981 views

Tool to detect errors in application's execution logic

I want to detect errors in application's execution logic. E.g.: forgot to call free() on address returned by malloc() did not close file handle returned by open() invalid flags passed to open() ...
zomega's user avatar
  • 1,022
0 votes
0 answers
29 views

How do I get this code to evaluate all arms of if-else? Why does Bash seem to interpret the characters that I input as integers? [duplicate]

The last elif arm does not get executed: #!/usr/bin/bash searches=("feet" "axilas" "lactant") length=${#searches[@]} searchFunction() { echo "Enter the respective ...
John Smith's user avatar
0 votes
0 answers
15 views

my if statement is returning command not found [duplicate]

in my script an if statement returns: line 3: []: command not found the statement: if ["$(pidof -x $(basename $0) -o %PPID)"]; then echo process already running; exit; fi what I tried: ...
andy's user avatar
  • 1
6 votes
1 answer
8k views

if ! <command> (...) vs. <command> ; if [ $? -eq 0 ] (...)

I am working on a shell script and decided to check my work via shellcheck.net. I am able to get functionally the same behavior of the following two lines in my script: findmnt /dev/sda1 >/dev/null ...
Kahn's user avatar
  • 1,827
2 votes
1 answer
423 views

Executing a remote script from a code repository causes endless loop

I often execute raw versions of remote Bash scripts in GitHub with this pattern: wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | ...
variable_expander's user avatar
0 votes
1 answer
44 views

Pausing script execution until user quits out of `less`

Goal: less the contents (from a variable) and then ask the user whether the contents should be saved to a file (i.e., .recovered_object) only after the user quits out of less. The excerpt from my ...
Per48edjes's user avatar
0 votes
2 answers
338 views

How to modify and write to file before printing to STDERR

I am working on an automated pull request check via GitHub actions and I want to preserve some data from a command's stderr output between jobs. For this, I need to write the stderr to an artifact ...
Abhishek Jain's user avatar
3 votes
5 answers
3k views

How to achieve an early exit from a code block in a bash script (analogous to perl's `last` directive)?

One feature of Perl that I really like is its generalization of looping control keywords to any curly-brace-delimited lexical block1. For example, one can use Perl's last directive to exit any such ...
kjo's user avatar
  • 16.4k
4 votes
2 answers
5k views

Return "continue" from function called from loop

I'm currently refactoring a script which has slowly grown beyond control. I'm trying to spin off repetition into functions. However, I have a repeated test being called from a loop, and want it to ...
Stripy42's user avatar
3 votes
2 answers
15k views

what is the use of script 2>/dev/null in the following script? [duplicate]

$!/bin/sh if grep "$1" /etc/passwd 2>/dev/null #Search username at beging of line1 then echo "Pattern found - Job Over" else echo "Pattern not found" fi
Shridhar B Waghamare's user avatar
7 votes
2 answers
1k views

How to know the code flow of a driver module?

I am studying Linux device drivers, my main focus is on wifi drivers. I want to know how the code flows when I plugin my device. Maybe, I can do something like add a printk line in every function. ...
Akshdeep Singh's user avatar

15 30 50 per page
1
2 3 4 5 6