Sponsored Content
Full Discussion: How does a if works in shell
Top Forums Shell Programming and Scripting How does a if works in shell Post 302576206 by frappa on Thursday 24th of November 2011 03:05:04 AM
Old 11-24-2011
Hi,

when comparing string (sorting) order replace the if..else conditional statement with:

Code:
[[ "$A" > "X10" ]] && echo "$A is correct" || echo "$A is incorrect"

Which basically means:
if the test inside the double square brackets returns true, display "$A is correct" else display "$A is incorrect".

You can find more about [[ ]] tests in bash man page, section 'Compound Commands'.

Keep in mind that you are comparing strings, so "X9" is actually > (that is, greater than) "X10".

see ya
fra

Last edited by frappa; 11-24-2011 at 04:07 AM.. Reason: added further explanation
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

substring command works but only in BASH shell

I am having trouble running a .sh file. The code 'x=${file_name:0:$z-11}' is giving me a bad substitution error. However when I run in BASH it works. Thing is when this goes to production the .sh will not be running in BASH. Is there a way to substring a string not in BASH or a way to invoke... (2 Replies)
Discussion started by: edwardtk11
2 Replies

2. Shell Programming and Scripting

Execution issue with shell script - works in a different environment

Hi I get the following error while executing the shell script. I did not get an error when I ran the script in a different environment (unix server). str-token.ksh: 0403-057 Syntax error at line 20 : `(' is not expected. This is the line which gives error string=(${pos_array}) Please find... (3 Replies)
Discussion started by: hidnana
3 Replies

3. Shell Programming and Scripting

Works in shell but not script UNIX

ok i have a very simple UNIX script #!/bin/bash TERM=ansi;export TERM PFCMARK=25;export PFCMARK umask 0000 PFUMASK=000;export PFUMASK #run for filepro menus and exectuables echo "###########File Modification Log.############\r" > "/public/appl-fp$(date +%m-%d-%Y).txt" find /appl/fp/... (10 Replies)
Discussion started by: dunpealslyr
10 Replies

4. Shell Programming and Scripting

how the typeset command works in shell script

typeset -l section section=${2:-.} what does these 2 lines meaning? (1 Reply)
Discussion started by: venkatababu
1 Replies

5. UNIX and Linux Applications

Rsync works in shell but not in cron

So I have this rsync script I wrote to grab some sql files and import them to a database. I left in the mysql stuff just give context to the situation. The real problem is with my rsync code. script.sh (chmod 744) #!/bin/sh rsync -av --rsh="sshpass -p'PASSWORD' ssh -l'USERNAME'"... (3 Replies)
Discussion started by: noPermissions
3 Replies

6. Shell Programming and Scripting

variable assigment not works in shell script

Hi, The following assigment is not working within shell script but is working from command line. Could anybody advise why? OS - solaris 8 APPL=`grep "$Application" ldapapps |awk '{print $1}'` echo $APPL (5 Replies)
Discussion started by: urello
5 Replies

7. Shell Programming and Scripting

perl: Command works in terminal, but not in shell script

Hi, the following command works in the terminal no problem. samtools view -h rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar... (8 Replies)
Discussion started by: jdilts
8 Replies

8. Shell Programming and Scripting

I am learning shell scripting and i would like to understand how sort -k3,3 -k 4,4 short* works

Please help me understand how sort -k3,3 -k 4,4 short* works , is it sorting 3 and 4 th field ? what is the use of specifying 3,3 and 4,4 in sort and what is actually does and i see sort -k3 short* and sort -k3,3 -k 4,4 short* giving the same output. Sort output attached Please help (2 Replies)
Discussion started by: Antony Ankrose
2 Replies

9. Shell Programming and Scripting

SUID works for shell scripts??

SUID works for shell scripts (bash)?? I'm user user1 need to execute a shell script (script.sh) which is owned by user2.-rwsrwxrwx 1 user2 aduser 3518 Aug 21 05:33 script.shOnly user2 has write privileges to write/copy a file in directory /dir1/subdir. Hence SUID bit permissions are set to... (8 Replies)
Discussion started by: MSK_1990
8 Replies

10. Shell Programming and Scripting

Need to understand how the line in perl program works as shell commend

I have a file with two line, one is header, the other actual value: TYPCD|ETID2|ETID|LEG ID|PTYP|PTYP SUB|TRD STATUS|CXL REASON|CACT|CACTNM|ENCD|ENC D NM|TRDR|ASDT|TRDT|MTDT|STDT|LS|SECID|SECID TYP|SECNM|PAR|STCC|MARKET PRICE|DIS MARKET PRICE|MARKET PRICE CURRENCY|SRC OF SETTLEMENT... (2 Replies)
Discussion started by: digioleg54
2 Replies
plmpower(8)							     powerman							       plmpower(8)

NAME
plmpower - control Insteon/X10 devices via SmartLabs PLM 2412S SYNOPSIS
plmpower --device serial-port DESCRIPTION
plmpower is a helper program for powerman which enables communication with Insteon/X10 devices via SmartLabs Power Line Modem, model 2412S. It is run interactively by the powerman daemon. It can also be useful as a standalone tool for debugging X10/Insteon networks based on the above device. NETWORK SETUP
Note the addresses of your Insteon/X10 devices. Plug the PLM into an AC outlet, preferably on the same electrical phase as the devices under control. Devices are available to bridge phases if this is not possible. Attach the PLM's serial port to your computer, and ensure that nothing else is using the serial port such as the system console or getty(8). Run plmpower and try the interactive commands below to see if the devices respond reliably. Once everything is working, configure powermand to run plmpower as a coprocess as described in powerman.conf(5). OPTIONS
-d, --device serial-port Specify the path to the special file connected to the PLM's serial port. -t, --timeout msec Set the Insteon timeout to the specified number of milliseconds (default 1000). -x, --x10-attempts number Set the number of times to run every X10 command (default 3). X10 does not provide an ACK/NAK mechanism like Insteon so we cannot be certain that any particular X10 command completed, therefore X10 commands are issued multiple times to increase confidence. INTERACTIVE COMMANDS
The following commands are accepted at the plmpower> prompt. Address arguments may be Insteon (e.g. 1A.2B.3C) or X10 (e.g. G12). help Display help on the available commands. info Get info about the PLM. reset Reset the PLM (clears the all-link db). on addr Turn on device. off addr Turn off device. status addr Query status of device (Insteon only). ping addr Time round trip request/response to device (Insteon only). FILES
/usr/sbin/plmpower /etc/powerman/powerman.conf ORIGIN
PowerMan was originally developed by Andrew Uselton on LLNL's Linux clusters. This software is open source and distributed under the terms of the GNU GPL. SEE ALSO
powerman(1), powermand(8), httppower(8), plmpower(8), vpcd(8), powerman.conf(5), powerman.dev(5), powerman-devices(7). http://sourceforge.net/projects/powerman powerman-2.3.5 2009-02-09 plmpower(8)
All times are GMT -4. The time now is 03:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy