Sponsored Content
Top Forums Shell Programming and Scripting Using grep with test and without using [[ ]] Post 303029166 by Xubuntu56 on Tuesday 22nd of January 2019 04:21:20 PM
Old 01-22-2019
Using grep with test and without using [[ ]]

As an exercise, I'm trying to re-write this code without the compound square brackets, using grep and test. Need to know what to do about the "equal-tilde".
Code:
#!/bin/bash
# test-integer2: evaluate the value of an integer.
INT=-5
if [[ "$INT" =~ ^-?[0-9]+$ ]]; then
if [ "$INT" -eq 0 ]; then
echo "INT is zero."
else
if [ "$INT" -lt 0 ]; then
echo "INT is negative."
else
echo "INT is positive."
fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using grep in a test/if statement

Okay, well this is more or less my first attempt at writing a shell script. Anyways, here's my code: cd ${PATH} if then rm ${FILE} ./anotherScript else exit 1 fi exit 1 Anyways, it's a pretty simple script that is supposed to search for the... (4 Replies)
Discussion started by: cbo0485
4 Replies

2. UNIX for Dummies Questions & Answers

Unix grep/test command

Hello, i have a script which checks if the user entered 8 numeric characters in the form of YYYYMMDD (birth date). If the user entered any non numeric characters, an error will be displayed: # Check to see if the 8 characters are all numbers # If not show error essage # And prompt user... (4 Replies)
Discussion started by: netmaster
4 Replies

3. Shell Programming and Scripting

Using grep inside a test

Hi, I want to use grep inside a test statement, but I am getting an error message. Two variables testvarNum=5 testvarNonNum=x echo $testvarNum | grep * The result of this is as follows: 5 However, when I try the following (i.e. to test if the variable is numeric or non-numeric):... (3 Replies)
Discussion started by: dkieran
3 Replies

4. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

5. Shell Programming and Scripting

grep functions, how to test if succeeded

Hello ...again. I am stuck on this part, I have a loop with processes an operations file. and calls different functions depending on what is in loop, which processes a database file... #so far my add function works as intended add() { ...blah blah; } # delete is kinda working... (13 Replies)
Discussion started by: gcampton
13 Replies

6. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

7. Shell Programming and Scripting

searching fileextentions (suffix) with grep and/or test

Hello, I have a problem. I will search files on fileextentions (suffix). It can with the command find, but I will do it with the commands grep and/or test. When i start the script I will see all files with that extention (suffix). Can anyone help me, please? Thanks! Regards, Arjan... (4 Replies)
Discussion started by: arjanengbers
4 Replies

8. Shell Programming and Scripting

If test grep.... always returns 0 status

Hi all. I am trying to compare and filter two files. I have a bigfile.txt of names and ids and a smallfile.txt of ids only. What I am trying to do is use a while read loop to read the ids in the bigfile and then echo the name and id only if the id exists in the small file. Basically, I'm trying to... (5 Replies)
Discussion started by: jameswatson3
5 Replies

9. Shell Programming and Scripting

Grep/print/ a test file

cat abc.txt Filename: SHA_AED_Monthly_SNR_20150331.txt.gz Data Format: ASCII with carriage returns and linefeeds Compression: GZIP GZIP Bytes: 36893068 Unzipped Bytes : 613794510 Records: 851310 Record Length: 738 Blocksize: 32472 Filename: SHA_AED_SNR_ChangeLog_20150331.txt.gz Data... (16 Replies)
Discussion started by: dotran
16 Replies

10. UNIX for Beginners Questions & Answers

Is it correct? if test grep EOF $a ...

read a if test grep EOF $a then echo yes file else echo no fi (1 Reply)
Discussion started by: iamsumibisht
1 Replies
CUBRID_LOB2_WRITE(3)							 1						      CUBRID_LOB2_WRITE(3)

cubrid_lob2_write - Write to a lob object.

SYNOPSIS
bool cubrid_lob2_write (resource $lob_identifier, string $buf) DESCRIPTION
The cubrid_lob2_write(3) function reads as much as data from $buf and stores it to the LOB object. Note that this function can only append characters now. PARAMETERS
o $lob_identifier -Lob identifier as a result of cubrid_lob2_new(3) or get from the result set. o $buf -Data that need to be written to the lob object. RETURN VALUES
TRUE if the process is successful and FALSE for failure. EXAMPLES
Example #1 cubrid_lob2_write(3) example 1 <?php // test_lob (id INT, contents CLOB) $conn = cubrid_connect("localhost", 33000, "demodb", "dba", ""); cubrid_execute($conn,"DROP TABLE if exists test_lob"); cubrid_execute($conn,"CREATE TABLE test_lob (id INT, contents CLOB)"); $req = cubrid_prepare($conn, "INSERT INTO test_lob VALUES(2, ?)"); $lob = cubrid_lob2_new($conn, 'CLOB'); $len = cubrid_lob2_write($lob, "Hello world"); cubrid_lob2_bind($req, 1, $lob); cubrid_execute($req); cubrid_disconnect($conn); ?> Example #2 cubrid_lob2_write(3) example 2 <?php // test_lob (id INT, contents CLOB) $conn = cubrid_connect("localhost", 33000, "demodb", "dba", ""); cubrid_execute($conn,"DROP TABLE if exists test_lob"); cubrid_execute($conn,"CREATE TABLE test_lob (id INT, contents CLOB)"); $req = cubrid_prepare($conn, "INSERT INTO test_lob VALUES(1, ?)"); $lob1 = cubrid_lob2_new($conn, 'CLOB'); $len = cubrid_lob2_write($lob1, "cubrid php driver"); cubrid_lob2_bind($req, 1, $lob1); cubrid_execute($req); $req = cubrid_execute($conn, "select * from test_lob"); $row = cubrid_fetch_row($req, CUBRID_LOB); $lob2 = $row[1]; cubrid_lob2_seek($lob2, 0, CUBRID_CURSOR_LAST); $pos = cubrid_lob2_tell($lob2); print "pos before write: $pos "; cubrid_lob2_write($lob2, "Hello world"); $pos = cubrid_lob2_tell($lob2); print "pos after write: $pos "; cubrid_disconnect($conn); ?> SEE ALSO
cubrid_lob2_read(3), cubrid_lob2_seek(3), cubrid_lob2_seek64(3), cubrid_lob2_tell(3), cubrid_lob2_tell64(3), cubrid_lob2_size(3), cubrid_lob2_size64(3). PHP Documentation Group CUBRID_LOB2_WRITE(3)
All times are GMT -4. The time now is 05:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy