Sponsored Content
Homework and Emergencies Homework & Coursework Questions UNIX script coding HW question Post 302894448 by sea on Tuesday 25th of March 2014 01:55:02 PM
Old 03-25-2014
Code:
[root@dell ~]# x=A
[root@dell ~]# [ $x = [aA] ] && echo "Add" 
[root@dell ~]# [ $x == [aA] ] && echo "Add" 
[root@dell ~]# [[ $x = [aA] ]] && echo "Add" 
Add
[root@dell ~]# [[ $x == [aA] ]] && echo "Add" 
Add
[root@dell ~]# echo $SHELL
/bin/bash

However:
Code:
[root@dell ~]# x=A
[root@dell ~]# x=${x,,}
[root@dell ~]# [ $x = a ] && echo "Add"
Add
[root@dell ~]#

So yes, for the REGEX you need the double brackets.
BTW: bad behaviour example as i was running it as root Smilie

Edit: Yes, for anything more complex than a simple single yes/no requires a standard if-statement like:
Code:
if [ $x -ge 100 ] || [[ "$x" == [aA] ]]
then    echo "Great"
else    echo "Low"
fi

BTW: The only 'place' i actualy use == (as it wont work properly with a single) is with PHP.
All of both the shells (sh,bash) i came across worked well with a single =.

EDIT2:
Just read (once more) the 'man bash', and beeing in the homework section Smilie i must say:
-> Better get used to use the proper syntax right from the start!

Last edited by sea; 03-25-2014 at 03:11 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unix Coding Standards

Hi, I am looking for some coding standards for Unix Shell Scripting. Can anyone help me out in this? Regards, Himanshu (3 Replies)
Discussion started by: himanshu_s
3 Replies

2. Shell Programming and Scripting

Shell Coding question for any experts out there

Given this one long stream of data (all one line): <TransactionDetail><TransactionHeader><ErrorLogging>YES</ErrorLogging><HistoryLogging>YES</HistoryLogging><ErrorDetection>NO</ErrorD... (4 Replies)
Discussion started by: dfran1972
4 Replies

3. Shell Programming and Scripting

Coding Standard For Unix Shell Scripting!!!

Is there any site on Coding Standard for Shell Scripting in UNIX. Please help me know!!!!! Thanks Om (1 Reply)
Discussion started by: Omkumar
1 Replies

4. UNIX for Dummies Questions & Answers

Unix coding tip required

Hi! Suppose I am at a location xyz:/abc1/abc2/abc3 Is it possible to move to another location xyz:/mnl1/mnl2/mnl3 by some coding within a script? (5 Replies)
Discussion started by: udiptya
5 Replies

5. Solaris

Getting Started in UNIX - incorporating C coding

I'm just starting a 'serious' coding in UNIX, so what I need is to run a C code on UNIX, What do I have to install (app) prior to coding/running the code and how do I compile that code? can I write my c code in UNIX or I need to have a visual studio for this? (7 Replies)
Discussion started by: Peevish
7 Replies

6. UNIX for Dummies Questions & Answers

Unix coding for triggering informatica

Hi, I have very little knowledge with unix and pmcmd. I need help with a issue. I have to see whether a file has been dropped in a particular location/path. If the file dropped I have to check the last modified time, which should be greater than 8pmEST the prior day. If the file has been... (4 Replies)
Discussion started by: redwolves
4 Replies

7. Shell Programming and Scripting

Need help in shell script coding

I have a file f1.txt that contains string: f1.txt aaa bbb ccc ... I want to write code to search that each string in file f2.txt(this file contains 1000+line codes). file f2.txt .. .. ....aaa...xyz.. ... ... ...ppp... (dots . can be characters ot blank spaces) If particular... (2 Replies)
Discussion started by: Sanchit
2 Replies

8. Shell Programming and Scripting

UNIX script coding help?

Unix script coding help? i am trying to write a code that will display following menu to user: (A) Add (B) Subtract (C) Multiply (D) Divide (E) Modulus (F) Exponentiation (G) Exit Then ask user for choice (A-F). After taking users choice ask user for two numbers and perform... (3 Replies)
Discussion started by: renegade755
3 Replies

9. UNIX for Dummies Questions & Answers

Help with understand shell script coding

Good afternoon everyone, I am very new to UNIX shell scripting and I am trying to understand the following code. I know what it does but I need to modify it so it will allow me to pass a file name as *FILENAME* Thank for any guidance offered. if ] ; then match=`expr "$file" :... (2 Replies)
Discussion started by: Walter Barona
2 Replies

10. What is on Your Mind?

Coding Style at UNIX.com forums

Hi, as I mentioned in this thread(https://www.unix.com/shell-programming-and-scripting/280737-awk-function-return-permutations-n-items-out-m.html), a helpful coding style may improve overall value and support for people who come here and want to learn things the participants from unix.com have... (2 Replies)
Discussion started by: stomp
2 Replies
math::complexnumbers(3tcl)					 Tcl Math Library					math::complexnumbers(3tcl)

__________________________________________________________________________________________________________________________________________________

NAME
math::complexnumbers - Straightforward complex number package SYNOPSIS
package require Tcl 8.3 package require math::complexnumbers ?1.0.2? ::math::complexnumbers::+ z1 z2 ::math::complexnumbers::- z1 z2 ::math::complexnumbers::* z1 z2 ::math::complexnumbers::/ z1 z2 ::math::complexnumbers::conj z1 ::math::complexnumbers::real z1 ::math::complexnumbers::imag z1 ::math::complexnumbers::mod z1 ::math::complexnumbers::arg z1 ::math::complexnumbers::complex real imag ::math::complexnumbers::tostring z1 ::math::complexnumbers::exp z1 ::math::complexnumbers::sin z1 ::math::complexnumbers::cos z1 ::math::complexnumbers::tan z1 ::math::complexnumbers::log z1 ::math::complexnumbers::sqrt z1 ::math::complexnumbers::pow z1 z2 _________________________________________________________________ DESCRIPTION
The mathematical module complexnumbers provides a straightforward implementation of complex numbers in pure Tcl. The philosophy is that the user knows he or she is dealing with complex numbers in an abstract way and wants as high a performance as can be had within the limita- tions of an interpreted language. Therefore the procedures defined in this package assume that the arguments are valid (representations of) "complex numbers", that is, lists of two numbers defining the real and imaginary part of a complex number (though this is a mere detail: rely on the complex command to con- struct a valid number.) Most procedures implement the basic arithmetic operations or elementary functions whereas several others convert to and from different rep- resentations: set z [complex 0 1] puts "z = [tostring $z]" puts "z**2 = [* $z $z] would result in: z = i z**2 = -1 AVAILABLE PROCEDURES
The package implements all or most basic operations and elementary functions. The arithmetic operations are: ::math::complexnumbers::+ z1 z2 Add the two arguments and return the resulting complex number complex z1 (in) First argument in the summation complex z2 (in) Second argument in the summation ::math::complexnumbers::- z1 z2 Subtract the second argument from the first and return the resulting complex number. If there is only one argument, the opposite of z1 is returned (i.e. -z1) complex z1 (in) First argument in the subtraction complex z2 (in) Second argument in the subtraction (optional) ::math::complexnumbers::* z1 z2 Multiply the two arguments and return the resulting complex number complex z1 (in) First argument in the multiplication complex z2 (in) Second argument in the multiplication ::math::complexnumbers::/ z1 z2 Divide the first argument by the second and return the resulting complex number complex z1 (in) First argument (numerator) in the division complex z2 (in) Second argument (denominator) in the division ::math::complexnumbers::conj z1 Return the conjugate of the given complex number complex z1 (in) Complex number in question Conversion/inquiry procedures: ::math::complexnumbers::real z1 Return the real part of the given complex number complex z1 (in) Complex number in question ::math::complexnumbers::imag z1 Return the imaginary part of the given complex number complex z1 (in) Complex number in question ::math::complexnumbers::mod z1 Return the modulus of the given complex number complex z1 (in) Complex number in question ::math::complexnumbers::arg z1 Return the argument ("angle" in radians) of the given complex number complex z1 (in) Complex number in question ::math::complexnumbers::complex real imag Construct the complex number "real + imag*i" and return it float real (in) The real part of the new complex number float imag (in) The imaginary part of the new complex number ::math::complexnumbers::tostring z1 Convert the complex number to the form "real + imag*i" and return the string float complex (in) The complex number to be converted Elementary functions: ::math::complexnumbers::exp z1 Calculate the exponential for the given complex argument and return the result complex z1 (in) The complex argument for the function ::math::complexnumbers::sin z1 Calculate the sine function for the given complex argument and return the result complex z1 (in) The complex argument for the function ::math::complexnumbers::cos z1 Calculate the cosine function for the given complex argument and return the result complex z1 (in) The complex argument for the function ::math::complexnumbers::tan z1 Calculate the tangent function for the given complex argument and return the result complex z1 (in) The complex argument for the function ::math::complexnumbers::log z1 Calculate the (principle value of the) logarithm for the given complex argument and return the result complex z1 (in) The complex argument for the function ::math::complexnumbers::sqrt z1 Calculate the (principle value of the) square root for the given complex argument and return the result complex z1 (in) The complex argument for the function ::math::complexnumbers::pow z1 z2 Calculate "z1 to the power of z2" and return the result complex z1 (in) The complex number to be raised to a power complex z2 (in) The complex power to be used BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category math :: complexnumbers of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. KEYWORDS
complex numbers, math CATEGORY
Mathematics COPYRIGHT
Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net> math 1.0.2 math::complexnumbers(3tcl)
All times are GMT -4. The time now is 06:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy