The problem is that within [[ ]] the == does a glob match rather than a string comparison.
In your case a \X in the glob pattern becomes a X and that differs.
Therefore, the right side of the == must be in quotes in order to escape the glob match and become a string match.
is sufficient; of course
looks better.
Compare with
where within [ ] the = always does a string comparison, but, because [ is a command, the shell first does a glob match against the current directory on both sides, and then compares the resulting strings. So both sides of the = must be in quotes.
Hi all,
I have a file like this
ibhib=ere
wefwfl=werfe
sfdes=wef
From this file, i need to get the lefthand side string with respect to the corresponding righthand side string. i.e, I need to get the string "ere" with respect to "ibhib".
But i am stuck with how to compare a string... (1 Reply)
Hi Guys
i need to write a script to check the file structure
I have added the the file headers in the configuration file and execute the file at the start of the script.
Now the function
checkFileStructure()
{
echo "Inside the function"
filetocheck=$1
fileheader=$2
if ]
then... (1 Reply)
I'm running the following script to compare string values to a regexp:
for entry in $(lpinfo -v | cut -c 1-); do
if
then
echo "blah"
continue
fi
done
Whenever I run it, each token of lpinfo is being interpreted as a command and I get errors such as:
... (2 Replies)
Is there a way to compare the permission string of two files and output the string if they match?
For ex:
-rw-r--r-- 1 user newuser 0 2009-03-12 16:45 file2
-rw-r--r-- 1 user newuser 0 2009-03-12 16:46 fileone
output:
-rw-r--r--
If they don't match output will be just... (3 Replies)
Hi ,
My requirement is to read from a file into a variable.
I need to check if the variable is equal to string "no rows selected".
The sh script snippet is as follows:
file=/data/lpgtwo/home/nikhilp/TriggerNames.txt
echo $file
var=`cat $file`
echo $var
if
then
echo "No... (3 Replies)
#!/bin/sh
PRINTF=/usr/bin/printf
MACHINE_NAME=`uname -n`
TIME=`date +"%H"`
$PRINTF "Welcome to $MACHINE_NAME. What is your name?\n"
read NAME
if ; then
$PRINTF "Good morning $NAME, how are you?\n"
elif ; then
$PRINTF "Good afternoon $NAME, how are you?\n"
else
$PRINTF "Good... (2 Replies)
continuing from my previous post, whose link is given below as a reference
https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569
consider there is create table commands in a file for eg:
CREATE TABLE `Blahblahblah` (
`id` int(11) NOT NULL... (2 Replies)
attempting the hangman program. This was an optional assignment from the professor. I have completed the logical coding, debugging now.
##I have an array $wordString that initializes to a string of dashes
##reflecting the number of letters in $theWord
##every time the user enters a (valid)... (5 Replies)
I have the logic below to look up for matches within the columns between the two files with awk.
In the if statement is where the string comparison is attempted with ==
The issue seems to be with the operands, as
1. when " '${SECTOR}' " -- double quote followed by single quote -- awk matches... (1 Reply)
Discussion started by: deadyetagain
1 Replies
LEARN ABOUT X11R4
open_memstream
OPEN_MEMSTREAM(3) Linux Programmer's Manual OPEN_MEMSTREAM(3)NAME
open_memstream, open_wmemstream - open a dynamic memory buffer stream
SYNOPSIS
#include <stdio.h>
FILE *open_memstream(char **ptr, size_t *sizeloc);
#include <wchar.h>
FILE *open_wmemstream(wchar_t **ptr, size_t *sizeloc);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
open_memstream(), open_wmemstream():
Since glibc 2.10:
_POSIX_C_SOURCE >= 200809L
Before glibc 2.10:
_GNU_SOURCE
DESCRIPTION
The open_memstream() function opens a stream for writing to a memory buffer. The function dynamically allocates the buffer, and the buffer
automatically grows as needed. Initially, the buffer has a size of zero. After closing the stream, the caller should free(3) this buffer.
The locations pointed to by ptr and sizeloc are used to report, respectively, the current location and the size of the buffer. The loca-
tions referred to by these pointers are updated each time the stream is flushed (fflush(3)) and when the stream is closed (fclose(3)).
These values remain valid only as long as the caller performs no further output on the stream. If further output is performed, then the
stream must again be flushed before trying to access these values.
A null byte is maintained at the end of the buffer. This byte is not included in the size value stored at sizeloc.
The stream maintains the notion of a current position, which is initially zero (the start of the buffer). Each write operation implicitly
adjusts the buffer position. The stream's buffer position can be explicitly changed with fseek(3) or fseeko(3). Moving the buffer posi-
tion past the end of the data already written fills the intervening space with null characters.
The open_wmemstream() is similar to open_memstream(), but operates on wide characters instead of bytes.
RETURN VALUE
Upon successful completion, open_memstream() and open_wmemstream() return a FILE pointer. Otherwise, NULL is returned and errno is set to
indicate the error.
VERSIONS
open_memstream() was already available in glibc 1.0.x. open_wmemstream() is available since glibc 2.4.
ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7).
+------------------+---------------+---------+
|Interface | Attribute | Value |
+------------------+---------------+---------+
|open_memstream(), | Thread safety | MT-Safe |
|open_wmemstream | | |
+------------------+---------------+---------+
CONFORMING TO
POSIX.1-2008. These functions are not specified in POSIX.1-2001, and are not widely available on other systems.
NOTES
There is no file descriptor associated with the file stream returned by these functions (i.e., fileno(3) will return an error if called on
the returned stream).
BUGS
In glibc before version 2.7, seeking past the end of a stream created by open_memstream() does not enlarge the buffer; instead the fseek(3)
call fails, returning -1.
EXAMPLE
See fmemopen(3).
SEE ALSO fmemopen(3), fopen(3), setbuf(3)COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the
latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
GNU 2017-09-15 OPEN_MEMSTREAM(3)