Linked Questions

282 votes
3 answers
57k views

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
Stéphane Chazelas's user avatar
32 votes
4 answers
30k views

Say there are hundreds of *.txt files in a directory. I only want to find the first three *.txt files and then exit the searching process. How can I achieve this using the find utility? I had a quick ...
mitnk's user avatar
  • 581
8 votes
9 answers
75k views

x=1 while [ $x -le 50 ] do echo $x $x=(($x + 1)) done I have wrote the above code. What seems to be a easy task in many programming languages is giving this error for me. solution.sh: line 5: ...
WannaBeCoder's user avatar
16 votes
2 answers
4k views

A well-formed printf usually has a format to use: $ var="Hello" $ printf '%s\n' "$var" Hello However, what could be the security implications of not providing a format? $ printf &...
user avatar
10 votes
3 answers
3k views

I know that it is possible to reverse "$@" using an array: arr=( "$@" ) And using this answer, reverse the array. But that requires a shell that has arrays. It is also possible using tac: set -- $(...
user avatar
7 votes
2 answers
2k views

I'm having some issues with a bash script, but I don't know why. The script is meant to convert the input (in minutes) to seconds and then start counting down until it reaches zero, at which point the ...
NeG's user avatar
  • 71
5 votes
4 answers
44k views

I have an if statement in a script. It looks like this: if [ "$a" != "0" -a "$b" != "100" ]; then #some commands here If I'm not mistaken, the line above will work if both conditions are true. ...
cube00's user avatar
  • 61
19 votes
1 answer
3k views

A few Bourne-like shells support associative arrays: ksh93 (since 1993), zsh (since 1998), bash (since 2009), though with some differences in behaviour between the 3. A common use is for counting ...
Stéphane Chazelas's user avatar
8 votes
2 answers
13k views

I was looking at discussion between Kusalananda and xhienne here, where it's mentioned [ "" -ge 2 ] not being a valid test producing an error in bash --posix and other POSIX-compliant shells. bash-4....
Sergiy Kolodyazhnyy's user avatar
12 votes
4 answers
17k views

What is the difference between these two Bash if-statements? e.g. if [ "$FOO" = "true" ]; then vs if [ $FOO = "true" ]; then What is the difference? It seems that both statements work the same.
Ryan's user avatar
  • 463
5 votes
3 answers
1k views

Sometime, it is not possible to have the luxury of bash on a system, but conditions are easier to make on bash compared to sh or ash, what one should verify to ensure condition won't break with ...
Zulgrib's user avatar
  • 1,054
5 votes
1 answer
23k views

var="$(command1 -l '$var2' -c 'command2|grep -c "search"')" if [[ var !=0 ]]; then fi Why am I getting "conditional binary operator expected". I searched already and. I. see that [[]] is a test ...
iControlEIP's user avatar
4 votes
1 answer
1k views

Say I connected to a Linux system as root. What exactly happens when I type unset *?
Lunartist's user avatar
  • 405
-1 votes
2 answers
375 views

Can some one tell me what is the meaning of each line with an example , I am not getting why regex is used and even [!0122...] #!/bin/sh is_integer () { case "${1#[+-]}" in (*[!...
disovox's user avatar
  • 35
2 votes
2 answers
1k views

When comparing a variable value to something (I'll take arithmetic comparison so that you can't use the "x$VAR" == "xyes" trick), how do I protect against the case when the ...
ivan_pozdeev's user avatar

15 30 50 per page