Sponsored Content
Full Discussion: Parsing null or empty output
Top Forums UNIX for Beginners Questions & Answers Parsing null or empty output Post 303009253 by MadeInGermany on Monday 11th of December 2017 12:58:18 PM
Old 12-11-2017
Quote:
Originally Posted by apmcd47
Code:
if [[ ${lastseen:-a} =~ [^0-9] ]]
then 
   echo "Serial number invalid"
   exit 3
fi

If lastseen is null or unset replace with an invalid string sequence. In this case the letter a will suffice.

Andrew
I call this a trick.
Nice somehow, but I am not going to recommend that as a common practice...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check for null or empty string

Hi, I need to check for value not equal (<>) to 21 and not equal empty or null values. Please modify this script if then echo "$VALUE,$BSC_NAME,$BSC_ID" > $OUT_FILE/power_up.out end if TQ (5 Replies)
Discussion started by: doer
5 Replies

2. Shell Programming and Scripting

Removing Null data in output

Hello all, I have a script that has an infile with system package information. For the most part the script is looking well. The only thing i need help is in testing for null entries and removing null data. #!/usr/bin/ksh for i in `cat /mwncps/bin/eco_pack` do NAME=`pkginfo -l |... (2 Replies)
Discussion started by: liketheshell
2 Replies

3. Shell Programming and Scripting

Table null is empty

hi I m executing a shell script in which records are to be fetched from a table. If the sql that is running empty result set it is displaying "table null is empty !". I dont want this msg on the standard output. COuld you please help me in this regard (3 Replies)
Discussion started by: priyanka3006
3 Replies

4. UNIX for Dummies Questions & Answers

cp output /dev/null results in not a directory

Hello, I am working on a script to measure the read performance of a busybox environment. The logical choice is to use a command line like: (time cp * /dev/null) 2> /tmp/howlong.txt Ah, the rub is cp or /dev/null will only accept a single file at a time. The result in the txt file is and... (1 Reply)
Discussion started by: stevesmo
1 Replies

5. Shell Programming and Scripting

PHP: how can I delete empty/NULL elements from a multi-dimensional array.

Hi all I have a file that i'm running and exec(cat ./dat) against..and putting its contents into any array, then doing an exploding the array into a multi-dimension array... The 15 multi-dimensional arrays have elements that are null/empty, I would like to remove/unset these elements and then... (2 Replies)
Discussion started by: zeekblack
2 Replies

6. Shell Programming and Scripting

Redirect system output to null in perl

Hi Guys, Please help me.. it is urgent. I am writing a perl script to capture command output and redirect it to a logfile.At the same i want to check the return code of the command and log it if the command is not succesful in my logfile.. Here is my code, it is working but system command inside... (2 Replies)
Discussion started by: sriramperumalla
2 Replies

7. Shell Programming and Scripting

redirect the audio output to /dev/null

I'm using an text-to-speech synthesis in a script, and I need to redirect it's output to /dev/null how can I do that ? And how to redirect the stream to his normal output then (sound card ) ? thankx (2 Replies)
Discussion started by: firelink
2 Replies

8. Shell Programming and Scripting

How to handle NULL value output from ISQL command?

I am using ISQL command in ksh script. Suppose if i get NULL value from the query which i run,how can i handle it? I am getting a NULL result set and the following error is coming. ############### output of isql command for getting the sum of JEs ################ ----------- NULL... (4 Replies)
Discussion started by: Sharma331
4 Replies

9. Shell Programming and Scripting

How to control a null output in EMC storage?

I dont want to print the output in a EMC VMAX storage if it says "The specified device was not found", however it is not letting me do it. I am trying to run this command: symaccess -sid xxxx list -type storage -devs 1234 output: The specified device was not found I just want the script... (1 Reply)
Discussion started by: prodigy06
1 Replies

10. Shell Programming and Scripting

Identify empty file with null record

Hi Team, I have a file abc.dat which is a empty file. But it has null record in first line. I need to identify this unique file and handle it separately. scenario 1: abc/dw> wc abc.dat 1 0 1 abc.dat abc/dw> cat abc.dat abc/dw> scenario 2: abc/dw> wc pqr.dat 0 0 0 pqr.dat... (3 Replies)
Discussion started by: kmanivan82
3 Replies
SHELL-QUOTE(1)						User Contributed Perl Documentation					    SHELL-QUOTE(1)

NAME
shell-quote - quote arguments for safe use, unmodified in a shell command SYNOPSIS
shell-quote [switch]... arg... DESCRIPTION
shell-quote lets you pass arbitrary strings through the shell so that they won't be changed by the shell. This lets you process commands or files with embedded white space or shell globbing characters safely. Here are a few examples. EXAMPLES
ssh preserving args When running a remote command with ssh, ssh doesn't preserve the separate arguments it receives. It just joins them with spaces and passes them to "$SHELL -c". This doesn't work as intended: ssh host touch 'hi there' # fails It creates 2 files, hi and there. Instead, do this: cmd=`shell-quote touch 'hi there'` ssh host "$cmd" This gives you just 1 file, hi there. process find output It's not ordinarily possible to process an arbitrary list of files output by find with a shell script. Anything you put in $IFS to split up the output could legitimately be in a file's name. Here's how you can do it using shell-quote: eval set -- `find -type f -print0 | xargs -0 shell-quote --` debug shell scripts shell-quote is better than echo for debugging shell scripts. debug() { [ -z "$debug" ] || shell-quote "debug:" "$@" } With echo you can't tell the difference between "debug 'foo bar'" and "debug foo bar", but with shell-quote you can. save a command for later shell-quote can be used to build up a shell command to run later. Say you want the user to be able to give you switches for a command you're going to run. If you don't want the switches to be re-evaluated by the shell (which is usually a good idea, else there are things the user can't pass through), you can do something like this: user_switches= while [ $# != 0 ] do case x$1 in x--pass-through) [ $# -gt 1 ] || die "need an argument for $1" user_switches="$user_switches "`shell-quote -- "$2"` shift;; # process other switches esac shift done # later eval "shell-quote some-command $user_switches my args" OPTIONS
--debug Turn debugging on. --help Show the usage message and die. --version Show the version number and exit. AVAILABILITY
The code is licensed under the GNU GPL. Check http://www.argon.org/~roderick/ or CPAN for updated versions. AUTHOR
Roderick Schertler <roderick@argon.org> perl v5.16.3 2010-06-11 SHELL-QUOTE(1)
All times are GMT -4. The time now is 06:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy