what does "$# -ne 4" mean in bash? [duplicate] - linux

This question already has answers here:
What does "-ne" mean in bash?
(3 answers)
Closed 3 years ago.
i am new to shell, I met a code "$# -ne 4". "$#" means the number of command-line arguments that were passed to the shell program, then what does "-ne" mean?

-ne in bash denotes 'not equal to'

Related

-n option in if statement in Linux [duplicate]

This question already has answers here:
Is there a list of 'if' switches anywhere?
(5 answers)
Closed 1 year ago.
What is the -n option in if statement in Linux?
Let's say there is a code:
if [ -n "$variable" ];then break;fi
What is it checking about the variable in if statement?
-n checks if the corresponding string variable (in your case $variable) is of non-zero length.

How do I use a variable with special characters in bash? [duplicate]

This question already has answers here:
How can I escape a double quote inside double quotes?
(9 answers)
Closed 1 year ago.
I have this variable in my bash script:
var="\'?"\"'\"
but when I type echo $var I get nothing. I want echo $var to return "\'?"\"'\". What should I do here?
You can try this
var="'''?\"\"\""
or
var='```?"""'
echo "$var"

How to write result in empty variable? [duplicate]

This question already has answers here:
Assignment of variables with space after the (=) sign?
(4 answers)
Closed 2 years ago.
How to write command result into empty variable?
#!/bin/bash
today=''
$today = $(date)
echo $today
There shouldn't be a space around the =
On variable assignment, no need for the $
#!/bin/bash
today=''
today="$(date)"
echo "${today}"

bash removes consecutive spaces from string [duplicate]

This question already has answers here:
I just assigned a variable, but echo $variable shows something else
(7 answers)
Closed 2 years ago.
I ran into a strange problem that I do not understand. Why are multiple spaces not present in the output of the following command?
$ d='A B'
$ echo $d
A B
use in double quotes:
echo "$d"

Why this shell script doesn't work? [duplicate]

This question already has answers here:
How do I iterate over a range of numbers defined by variables in Bash?
(20 answers)
Closed 9 years ago.
n=5
for i in {1..$[n]}
do
echo $i
done
it gives:
{1..5}
But I think it should output:
1
2
3
4
5
Why it gives such a strange output?
That is almost a riddle. The expansion of the braces is being done prior to the variable expansion. The bash beginners guide has some good detail on expansion
There are a brazillion ways to do this in bash.
You could start with:
n=5
for i in $(eval echo {1..$n})
do
echo $i
done

Resources