If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below. ** If you are logged in, most ads will not be displayed. **

Thanks,
Allow me to clarify my question a bit. I have some longer conditionals involving a few commands, and the result is going to either $? or a variable.
So I wanted to understand if $? is always a char type, so I need to use bash's lexical compare, or an integer so I need to do an arithmetic compare.
I guess the source of my confusion is that a program exit(int) takes an integer argument. Then is $? an integer then or is it always a char?
Similarly, does grep -c return a char (string) or a integer?
Regards,
B

So shells emit character strings, and it is up to other programs to convert these to internal form (binary) in order to compare values arithmetically, if that is desired. As watael wrote, there are different operators for string comparison and arithmetic comparison.

Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

results in ASCII output but this does not necessary have anything to do if $a internally is an integer or a string. BASH is unfortunately a "weak typed language" that internally indeed uses "strings" and "integers". See "Advanced Bash-Scripting Guide" There is a bash statement

1
"==" and "!=" always work, no need for "-eq" and "-ne" (this we already knew!)
2
If variables are explicitly declared as integers this affects the result of arithmetic expressions

I guess:

If you don't use "declare -i" statements the user can assume that all variables are strings. Possible internal uses of integers are then transparent and of no concern for the users! From the point of view of the user it is then not a "weakly typed language"

Unlike many other programming languages, Bash does not segregate its variables by "type." Essentially, Bash variables are character strings, but, depending on context, Bash permits arithmetic operations and comparisons on variables. The determining factor is whether the value of a variable contains only digits.

When comparing a value such as "2" against "02", you may see the utility of comparison operators "-eq", "-ne", as opposed to the string comparison operators.

Best wishes ... cheers, drl

Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )