Linked Questions

13 votes
2 answers
10k views

At this question in the answer from Kyle Brandt the [[ ]] construct is described as a "bash built-in test command". The following is shown as an example. if [[ ( $a -gt 2 ) && ( $a -lt 5 )...
H2ONaCl's user avatar
  • 11.5k
0 votes
0 answers
3k views

I have a problem with bash, I'm trying to detect strings in a file with bash with the file looking like cnlog "Hello World!" When i try the [ $variable = *" ] in bash it doesn't work ...
decipher's user avatar
2 votes
1 answer
572 views

Assume a user fed time : read -p "Enter the start time you want to start(hh:mm:ss) " user_start_time and the regex : timePattern="[0-2][0-3]:[0-5][0-9]:[0-5][0-9]" if i do : if [ "$user_start_time"...
NoobEditor's user avatar
-1 votes
1 answer
224 views

I was trying to use a bash script to validate some strings. No matter what I've tried, the script ends up matching every string provided as input and it's printing yes in the terminal. For example, ...
captain vhagar's user avatar
0 votes
0 answers
62 views

I am trying some simple input validation in bash. Basically this part of my script outputs "press [index] to select [array element]." However I cannot seem to get it to stop and exit ...
Andy's user avatar
  • 225
0 votes
0 answers
49 views

I have a simple for-loop that iterates over a glob-pattern and enters an if condition, for when the directory path is not equal to */venv then print the file. How can I get this working in the if ...
Emil11's user avatar
  • 309
2270 votes
21 answers
1.9m views

How do I iterate over a range of numbers in Bash when the range is given by a variable? I know I can do this (called "sequence expression" in the Bash documentation): for i in {1..5}; do ...
eschercycle's user avatar
  • 23.6k
1915 votes
11 answers
884k views

When writing shell programs, we often use /bin/sh and /bin/bash. I usually use bash, but I don't know what's the difference between them. What's the main difference between Bash and sh? What do we ...
Weiwei Yang's user avatar
  • 19.3k
342 votes
9 answers
263k views

I'm trying to learn shell scripting, and I need to understand someone else's code. What is the $? variable hold? I can't Google search the answer because they block punctuation characters.
David Mulder's user avatar
  • 8,116
357 votes
8 answers
338k views

What does echo $? mean in shell programming?
Harshay Buradkar's user avatar
266 votes
7 answers
224k views

I've seen Bash scripts test for a non-zero length string in two different ways. Most scripts use the -n option: #!/bin/bash # With the -n option if [ -n "$var" ]; then # Do something when var is ...
AllenHalsey's user avatar
  • 2,661
113 votes
4 answers
145k views

My whole script is currently this: #!/bin/sh clear; blanko=""; # Dummy-Variablen variable=Testvariable; if [[$variable == $blanko]]; then echo "Nichts da!" else ...
EpsilonAlpha's user avatar
  • 1,233
49 votes
6 answers
43k views

In Bash, is there a simple way to test if one string is lexicographically less than or equal to another? I know you can do: if [[ "a" < "b" ]] for testing strict inequality, or if [[ 1 -le 1 ]] ...
tskuzzy's user avatar
  • 36.6k
39 votes
2 answers
15k views

I see here that testing whether $? is zero (success) or something else (failure) is an anti-pattern, but I have not been able to find this anywhere else. Sticking to the definition of anti-pattern of ...
svye's user avatar
  • 493
0 votes
1 answer
6k views

So yes I am doing this for school but I have most of the script written. I don't know what's going on with it, maybe a syntax error but it keeps messing up(or I do). The first issue is that it keeps ...
troylatroy's user avatar

15 30 50 per page