first of all, don't hesitate to notify me if I misbehave. I'm a newbe in the use of this site, and in unix too (in english as well :-)
Well, if someone hat a little time to waste, could he explain to me this strange behavior.
I'm using ksh under AIX.
Code:
cdeset=$(su - db2inst1 -c "db2 get db cfg")
echo "$cdeset"|grep -i 'code page'
Database code page = 819
This works fine. But the following doesn't :
Code:
echo "$(su - db2inst1 -c 'db2 get db cfg')"|grep -i 'code page'
Nothing echoed...
I can't understand.
Code:
echo "$(su - db2inst1 -c 'db2 get db cfg')"
works fine... A string is sent to STDOUT.
Redirected to 'grep', that shoul work no ?
OK, thanks for reading...
JC
Moderator's Comments:
Please use code tags next time for your code and data, thanks
The second version "loses" carriage control: the \n characters are not there. So all of the output is one single line that grep will not print because it has 'code page' in it. The first example creates multiple lines of output as your example shows
Please post the result of echo "$(su - db2inst1 -c 'db2 get db cfg')" with and without double quotes.
Could you put the pipe to grep into the command substitution?
duntstudb51:root:/home/jc # echo "$(su - db2inst1 -c 'db2 get db cfg')"
Database Configuration for Database
Database configuration release level = 0x1000
Database release level = 0x1000
Database territory = FR
Database code page = 819
Database code set = ISO8859-1
Database country/region code = 33
Database collating sequence = UNIQUE
Alternate collating sequence (ALT_COLLATE) =
Number compatibility = OFF
Varchar2 compatibility = OFF
Date compatibility = OFF
Database page size = 4096
Statement concentrator (STMT_CONC) = OFF
Discovery support for this database (DISCOVER_DB) = ENABLE
Restrict access = NO
Default query optimization class (DFT_QUERYOPT) = 5
Degree of parallelism (DFT_DEGREE) = 1
Continue upon arithmetic exceptions (DFT_SQLMATHWARN) = NO
Default refresh age (DFT_REFRESH_AGE) = 0
Default maintained table types for opt (DFT_MTTB_TYPES) = SYSTEM
Number of frequent values retained (NUM_FREQVALUES) = 10
Number of quantiles retained (NUM_QUANTILES) = 20
Decimal floating point rounding mode (DECFLT_ROUNDING) = ROUND_HALF_EVEN
Backup pending = NO
All committed transactions have been written to disk = NO
Rollforward pending = NO
Restore pending = NO
Multi-page file allocation enabled = YES
Log retain for recovery status = NO
User exit for logging status = NO
Self tuning memory (SELF_TUNING_MEM) = ON
Size of database shared memory (4KB) (DATABASE_MEMORY) = AUTOMATIC(125884)
Database memory threshold (DB_MEM_THRESH) = 100
Max storage for lock list (4KB) (LOCKLIST) = AUTOMATIC(13504)
Percent. of lock lists per application (MAXLOCKS) = AUTOMATIC(97)
Package cache size (4KB) (PCKCACHESZ) = AUTOMATIC(641)
Sort heap thres for shared sorts (4KB) (SHEAPTHRES_SHR) = AUTOMATIC(5027)
Sort list heap (4KB) (SORTHEAP) = AUTOMATIC(1006)
Database heap (4KB) (DBHEAP) = AUTOMATIC(4565)
Catalog cache size (4KB) (CATALOGCACHE_SZ) = 300
Log buffer size (4KB) (LOGBUFSZ) = 2149
Utilities heap size (4KB) (UTIL_HEAP_SZ) = AUTOMATIC(13069)
SQL statement heap (4KB) (STMTHEAP) = AUTOMATIC(8192)
Default application heap (4KB) (APPLHEAPSZ) = AUTOMATIC(256)
Application Memory Size (4KB) (APPL_MEMORY) = AUTOMATIC(40000)
Statistics heap size (4KB) (STAT_HEAP_SZ) = AUTOMATIC(4384)
Interval for checking deadlock (ms) (DLCHKTIME) = 10000
Lock timeout (sec) (LOCKTIMEOUT) = -1
Changed pages threshold (CHNGPGS_THRESH) = 80
Number of asynchronous page cleaners (NUM_IOCLEANERS) = AUTOMATIC(2)
Number of I/O servers (NUM_IOSERVERS) = AUTOMATIC(12)
Sequential detect flag (SEQDETECT) = YES
Default prefetch size (pages) (DFT_PREFETCH_SZ) = AUTOMATIC
Track modified pages (TRACKMOD) = NO
Default number of containers = 1
Default tablespace extentsize (pages) (DFT_EXTENT_SZ) = 32
Max number of active applications (MAXAPPLS) = AUTOMATIC(40)
Average number of active applications (AVG_APPLS) = AUTOMATIC(1)
Max DB files open per application (MAXFILOP) = 61440
Log file size (4KB) (LOGFILSIZ) = 1024
Number of primary log files (LOGPRIMARY) = 13
Number of secondary log files (LOGSECOND) = 12
Changed path to log files (NEWLOGPATH) = /udb/db2inst1/log/NODE0000/LOGSTREAM0000/
Path to log files = /udb/db2inst1/data/db2inst1/NODE0000/SQL00001/LOGSTREAM0000/
Overflow log path (OVERFLOWLOGPATH) =
Mirror log path (MIRRORLOGPATH) =
First active log file =
Block log on disk full (BLK_LOG_DSK_FUL) = NO
Block non logged operations (BLOCKNONLOGGED) = NO
Percent max primary log space by transaction (MAX_LOG) = 0
Num. of active log files for 1 active UOW(NUM_LOG_SPAN) = 0
Percent log file reclaimed before soft chckpt (SOFTMAX) = 0
Target for oldest page in LBP (PAGE_AGE_TRGT_MCR) = 120
Target for oldest page in GBP (PAGE_AGE_TRGT_GCR) = 240
HADR database role = STANDARD
HADR local host name (HADR_LOCAL_HOST) =
HADR local service name (HADR_LOCAL_SVC) =
HADR remote host name (HADR_REMOTE_HOST) =
HADR remote service name (HADR_REMOTE_SVC) =
HADR instance name of remote server (HADR_REMOTE_INST) =
HADR timeout value (HADR_TIMEOUT) = 120
HADR target list (HADR_TARGET_LIST) =
HADR log write synchronization mode (HADR_SYNCMODE) = ASYNC
HADR spool log data limit (4KB) (HADR_SPOOL_LIMIT) = AUTOMATIC(0)
HADR log replay delay (seconds) (HADR_REPLAY_DELAY) = 0
HADR peer window duration (seconds) (HADR_PEER_WINDOW) = 0
First log archive method (LOGARCHMETH1) = DISK:/udb/db2inst1/log_archive/
Archive compression for logarchmeth1 (LOGARCHCOMPR1) = OFF
Options for logarchmeth1 (LOGARCHOPT1) =
Second log archive method (LOGARCHMETH2) = OFF
Archive compression for logarchmeth2 (LOGARCHCOMPR2) = OFF
Options for logarchmeth2 (LOGARCHOPT2) =
Failover log archive path (FAILARCHPATH) =
Number of log archive retries on error (NUMARCHRETRY) = 5
Log archive retry Delay (secs) (ARCHRETRYDELAY) = 20
Vendor options (VENDOROPT) =
Auto restart enabled (AUTORESTART) = ON
Index re-creation time and redo index build (INDEXREC) = SYSTEM (RESTART)
Log pages during index build (LOGINDEXBUILD) = OFF
Default number of loadrec sessions (DFT_LOADREC_SES) = 1
Number of database backups to retain (NUM_DB_BACKUPS) = 12
Recovery history retention (days) (REC_HIS_RETENTN) = 366
Auto deletion of recovery objects (AUTO_DEL_REC_OBJ) = OFF
TSM management class (TSM_MGMTCLASS) =
TSM node name (TSM_NODENAME) =
TSM owner (TSM_OWNER) =
TSM password (TSM_PASSWORD) =
Automatic maintenance (AUTO_MAINT) = ON
Automatic database backup (AUTO_DB_BACKUP) = OFF
Automatic table maintenance (AUTO_TBL_MAINT) = ON
Automatic runstats (AUTO_RUNSTATS) = ON
Real-time statistics (AUTO_STMT_STATS) = ON
Statistical views (AUTO_STATS_VIEWS) = OFF
Automatic sampling (AUTO_SAMPLING) = OFF
Automatic reorganization (AUTO_REORG) = OFF
Auto-Revalidation (AUTO_REVAL) = DEFERRED
CF Resource Configuration:
CF self-tuning memory = OFF
CF database memory size (4KB) (CF_DB_MEM_SZ) = AUTOMATIC(32768)
Group buffer pool size (4KB) (CF_GBP_SZ) = AUTOMATIC(7936)
Global lock memory size (4KB) (CF_LOCK_SZ) = AUTOMATIC(16384)
Shared communication area size (4KB) (CF_SCA_SZ) = AUTOMATIC(6912)
Catch up target for secondary CF (mins)(CF_CATCHUP_TRGT) = AUTOMATIC(15)
Currently Committed (CUR_COMMIT) = ON
CHAR output with DECIMAL input (DEC_TO_CHAR_FMT) = NEW
Enable XML Character operations (ENABLE_XMLCHAR) = YES
WLM Collection Interval (minutes) (WLM_COLLECT_INT) = 0
Monitor Collect Settings
Request metrics (MON_REQ_METRICS) = BASE
Activity metrics (MON_ACT_METRICS) = BASE
Object metrics (MON_OBJ_METRICS) = EXTENDED
Routine data (MON_RTN_DATA) = NONE
Routine executable list (MON_RTN_EXECLIST) = OFF
Unit of work events (MON_UOW_DATA) = NONE
UOW events with package list (MON_UOW_PKGLIST) = OFF
UOW events with executable list (MON_UOW_EXECLIST) = OFF
Lock timeout events (MON_LOCKTIMEOUT) = NONE
Deadlock events (MON_DEADLOCK) = WITHOUT_HIST
Lock wait events (MON_LOCKWAIT) = NONE
Lock wait event threshold (MON_LW_THRESH) = 5000000
Number of package list entries (MON_PKGLIST_SZ) = 32
Lock event notification level (MON_LCK_MSG_LVL) = 1
SMTP Server (SMTP_SERVER) =
SQL conditional compilation flags (SQL_CCFLAGS) =
Section actuals setting (SECTION_ACTUALS) = NONE
Connect procedure (CONNECT_PROC) =
Adjust temporal SYSTEM_TIME period (SYSTIME_PERIOD_ADJ) = NO
Log DDL Statements (LOG_DDL_STMTS) = NO
Log Application Information (LOG_APPL_INFO) = NO
Default data capture on new Schemas (DFT_SCHEMAS_DCC) = NO
Default table organization (DFT_TABLE_ORG) = ROW
Default string units (STRING_UNITS) = SYSTEM
National character string mapping (NCHAR_MAPPING) = NOT APPLICABLE
Database is in write suspend state = NO
Extended row size support (EXTENDED_ROW_SZ) = ENABLE
Optimize directed workloads (OPT_DIRECT_WRKLD) = NO
Encryption Library for Backup (ENCRLIB) =
Encryption Options for Backup (ENCROPTS) =
Encrypted database = NO
Procedural language stack trace (PL_STACK_TRACE) = NONE
and without double quotes :
Code:
duntstudb51:root:/home/jc # echo $(su - db2inst1 -c 'db2 get db cfg')
Database Configuration for Database Database configuration release level = 0x1000 Database release level = 0x1000 Database territory = FR Database code page = 819 Database code set = ISO8859-1 Database country/region code = 33 Database collating sequence = UNIQUE Alternate collating sequence (ALT_COLLATE) = Number compatibility = OFF Varchar2 compatibility = OFF Date compatibility = OFF Database page size = 4096 Statement concentrator (STMT_CONC) = OFF Discovery support for this database (DISCOVER_DB) = ENABLE Restrict access = NO Default query optimization class (DFT_QUERYOPT) = 5 Degree of parallelism (DFT_DEGREE) = 1 Continue upon arithmetic exceptions (DFT_SQLMATHWARN) = NO Default refresh age (DFT_REFRESH_AGE) = 0 Default maintained table types for opt (DFT_MTTB_TYPES) = SYSTEM Number of frequent values retained (NUM_FREQVALUES) = 10 Number of quantiles retained (NUM_QUANTILES) = 20 Decimal floating point rounding mode (DECFLT_ROUNDING) = ROUND_HALF_EVEN Backup pending = NO All committed transactions have been written to disk = NO Rollforward pending = NO Restore pending = NO Multi-page file allocation enabled = YES Log retain for recovery status = NO User exit for logging status = NO Self tuning memory (SELF_TUNING_MEM) = ON Size of database shared memory (4KB) (DATABASE_MEMORY) = AUTOMATIC(125884) Database memory threshold (DB_MEM_THRESH) = 100 Max storage for lock list (4KB) (LOCKLIST) = AUTOMATIC(13504) Percent. of lock lists per application (MAXLOCKS) = AUTOMATIC(97) Package cache size (4KB) (PCKCACHESZ) = AUTOMATIC(641) Sort heap thres for shared sorts (4KB) (SHEAPTHRES_SHR) = AUTOMATIC(5027) Sort list heap (4KB) (SORTHEAP) = AUTOMATIC(1006) Database heap (4KB) (DBHEAP) = AUTOMATIC(4565) Catalog cache size (4KB) (CATALOGCACHE_SZ) = 300 Log buffer size (4KB) (LOGBUFSZ) = 2149 Utilities heap size (4KB) (UTIL_HEAP_SZ) = AUTOMATIC(13069) SQL statement heap (4KB) (STMTHEAP) = AUTOMATIC(8192) Default application heap (4KB) (APPLHEAPSZ) = AUTOMATIC(256) Application Memory Size (4KB) (APPL_MEMORY) = AUTOMATIC(40000) Statistics heap size (4KB) (STAT_HEAP_SZ) = AUTOMATIC(4384) Interval for checking deadlock (ms) (DLCHKTIME) = 10000 Lock timeout (sec) (LOCKTIMEOUT) = -1 Changed pages threshold (CHNGPGS_THRESH) = 80 Number of asynchronous page cleaners (NUM_IOCLEANERS) = AUTOMATIC(2) Number of I/O servers (NUM_IOSERVERS) = AUTOMATIC(12) Sequential detect flag (SEQDETECT) = YES Default prefetch size (pages) (DFT_PREFETCH_SZ) = AUTOMATIC Track modified pages (TRACKMOD) = NO Default number of containers = 1 Default tablespace extentsize (pages) (DFT_EXTENT_SZ) = 32 Max number of active applications (MAXAPPLS) = AUTOMATIC(40) Average number of active applications (AVG_APPLS) = AUTOMATIC(1) Max DB files open per application (MAXFILOP) = 61440 Log file size (4KB) (LOGFILSIZ) = 1024 Number of primary log files (LOGPRIMARY) = 13 Number of secondary log files (LOGSECOND) = 12 Changed path to log files (NEWLOGPATH) = /udb/db2inst1/log/NODE0000/LOGSTREAM0000/ Path to log files = /udb/db2inst1/data/db2inst1/NODE0000/SQL00001/LOGSTREAM0000/ Overflow log path (OVERFLOWLOGPATH) = Mirror log path (MIRRORLOGPATH) = First active log file = Block log on disk full (BLK_LOG_DSK_FUL) = NO Block non logged operations (BLOCKNONLOGGED) = NO Percent max primary log space by transaction (MAX_LOG) = 0 Num. of active log files for 1 active UOW(NUM_LOG_SPAN) = 0 Percent log file reclaimed before soft chckpt (SOFTMAX) = 0 Target for oldest page in LBP (PAGE_AGE_TRGT_MCR) = 120 Target for oldest page in GBP (PAGE_AGE_TRGT_GCR) = 240 HADR database role = STANDARD HADR local host name (HADR_LOCAL_HOST) = HADR local service name (HADR_LOCAL_SVC) = HADR remote host name (HADR_REMOTE_HOST) = HADR remote service name (HADR_REMOTE_SVC) = HADR instance name of remote server (HADR_REMOTE_INST) = HADR timeout value (HADR_TIMEOUT) = 120 HADR target list (HADR_TARGET_LIST) = HADR log write synchronization mode (HADR_SYNCMODE) = ASYNC HADR spool log data limit (4KB) (HADR_SPOOL_LIMIT) = AUTOMATIC(0) HADR log replay delay (seconds) (HADR_REPLAY_DELAY) = 0 HADR peer window duration (seconds) (HADR_PEER_WINDOW) = 0 First log archive method (LOGARCHMETH1) = DISK:/udb/db2inst1/log_archive/ Archive compression for logarchmeth1 (LOGARCHCOMPR1) = OFF Options for logarchmeth1 (LOGARCHOPT1) = Second log archive method (LOGARCHMETH2) = OFF Archive compression for logarchmeth2 (LOGARCHCOMPR2) = OFF Options for logarchmeth2 (LOGARCHOPT2) = Failover log archive path (FAILARCHPATH) = Number of log archive retries on error (NUMARCHRETRY) = 5 Log archive retry Delay (secs) (ARCHRETRYDELAY) = 20 Vendor options (VENDOROPT) = Auto restart enabled (AUTORESTART) = ON Index re-creation time and redo index build (INDEXREC) = SYSTEM (RESTART) Log pages during index build (LOGINDEXBUILD) = OFF Default number of loadrec sessions (DFT_LOADREC_SES) = 1 Number of database backups to retain (NUM_DB_BACKUPS) = 12 Recovery history retention (days) (REC_HIS_RETENTN) = 366 Auto deletion of recovery objects (AUTO_DEL_REC_OBJ) = OFF TSM management class (TSM_MGMTCLASS) = TSM node name (TSM_NODENAME) = TSM owner (TSM_OWNER) = TSM password (TSM_PASSWORD) = Automatic maintenance (AUTO_MAINT) = ON Automatic database backup (AUTO_DB_BACKUP) = OFF Automatic table maintenance (AUTO_TBL_MAINT) = ON Automatic runstats (AUTO_RUNSTATS) = ON Real-time statistics (AUTO_STMT_STATS) = ON Statistical views (AUTO_STATS_VIEWS) = OFF Automatic sampling (AUTO_SAMPLING) = OFF Automatic reorganization (AUTO_REORG) = OFF Auto-Revalidation (AUTO_REVAL) = DEFERRED CF Resource Configuration: CF self-tuning memory = OFF CF database memory size (4KB) (CF_DB_MEM_SZ) = AUTOMATIC(32768) Group buffer pool size (4KB) (CF_GBP_SZ) = AUTOMATIC(7936) Global lock memory size (4KB) (CF_LOCK_SZ) = AUTOMATIC(16384) Shared communication area size (4KB) (CF_SCA_SZ) = AUTOMATIC(6912) Catch up target for secondary CF (mins)(CF_CATCHUP_TRGT) = AUTOMATIC(15) Currently Committed (CUR_COMMIT) = ON CHAR output with DECIMAL input (DEC_TO_CHAR_FMT) = NEW Enable XML Character operations (ENABLE_XMLCHAR) = YES WLM Collection Interval (minutes) (WLM_COLLECT_INT) = 0 Monitor Collect Settings Request metrics (MON_REQ_METRICS) = BASE Activity metrics (MON_ACT_METRICS) = BASE Object metrics (MON_OBJ_METRICS) = EXTENDED Routine data (MON_RTN_DATA) = NONE Routine executable list (MON_RTN_EXECLIST) = OFF Unit of work events (MON_UOW_DATA) = NONE UOW events with package list (MON_UOW_PKGLIST) = OFF UOW events with executable list (MON_UOW_EXECLIST) = OFF Lock timeout events (MON_LOCKTIMEOUT) = NONE Deadlock events (MON_DEADLOCK) = WITHOUT_HIST Lock wait events (MON_LOCKWAIT) = NONE Lock wait event threshold (MON_LW_THRESH) = 5000000 Number of package list entries (MON_PKGLIST_SZ) = 32 Lock event notification level (MON_LCK_MSG_LVL) = 1 SMTP Server (SMTP_SERVER) = SQL conditional compilation flags (SQL_CCFLAGS) = Section actuals setting (SECTION_ACTUALS) = NONE Connect procedure (CONNECT_PROC) = Adjust temporal SYSTEM_TIME period (SYSTIME_PERIOD_ADJ) = NO Log DDL Statements (LOG_DDL_STMTS) = NO Log Application Information (LOG_APPL_INFO) = NO Default data capture on new Schemas (DFT_SCHEMAS_DCC) = NO Default table organization (DFT_TABLE_ORG) = ROW Default string units (STRING_UNITS) = SYSTEM National character string mapping (NCHAR_MAPPING) = NOT APPLICABLE Database is in write suspend state = NO Extended row size support (EXTENDED_ROW_SZ) = ENABLE Optimize directed workloads (OPT_DIRECT_WRKLD) = NO Encryption Library for Backup (ENCRLIB) = Encryption Options for Backup (ENCROPTS) = Encrypted database = NO Procedural language stack trace (PL_STACK_TRACE) = NONE
duntstudb51:root:/home/jc #
I made different searches in google. I found, this afternoon, what seems to be a bug in a ksh version. They say that it's impossible to put a pipe inside the command substitution. But for me, this can't be the problem. That works with this for instance :
The grep utility is defined to work on text files. By definition, a text file contains lines that are no longer than LINE_MAX bytes (2048 on many systems). When you quote the expansion of your variable, the lines are preserved and no line fed to grep is longer than LINE_MAX. So:
Code:
cdeset=$(su - db2inst1 -c "db2 get db cfg")
echo "$cdeset"|grep -i 'code page'
works and:
Code:
cdeset=$(su - db2inst1 -c "db2 get db cfg" | grep -i 'code page')
should also work with no problems. But:
Code:
cdeset=$(su - db2inst1 -c "db2 get db cfg")
echo $cdeset | grep -i 'code page'
(with no quotes around the expansion of $cdeset) feeds one very long line to grep and produces unspecified results. (No output is a valid result in this case. Printing the entire long line is another valid result in this case. Printing a diagnostic message saying the input is not a text file is a valid result in this case. Printing a line saying: bad programmer is another valid result in this case, although I don't know of any version of grep that implements this option.)
The Korn shell (i.e., ksh) does not have any problem with pipelines inside command substitutions as long as the data fed through the pipeline is in a format that is suitable to each of the commands in the pipeline. Feeding data through a pipeline in a format that is not valid for a command reading it in a pipeline might or might not work in a command substitution and might or might not work in a pipeline outside of a command substitution. I don't know of any shell where a pipeline inside a command substitution would behave differently than the same pipeline outside a command substitution (other than side effects affecting the current shell execution environment will disappear when a pipeline in a command substitution completes).
Hi Guys,
I need to replace the string based on specific value by keeping dollar sign
input=$1
var=$(echo "@code_temp_table_$value_table"| sed -r "s/\@code/${input}/;s/(nz|sa)_\$value_/\$value1_\1_/" )
Expected
if
input=nz,sa
then
nz_temp_table_$value1_table
else
if any other... (5 Replies)
Hi experts. I want to setup a training lab.
I have a Power 5 standalone server 9110-51A (p5 510)
I want to enable PowerVM on it and create two LPARs
I don't have money for an HMC
I know I can use IVM instead
I understand IVM is part of the VIOS software
TWO QUESTIONS:
1- If... (12 Replies)
hi,
I have been trying to acheive the following task for a while now, but failed.. Need help, experts please help!
This is what I am trying to do:
- I am writing to a flat file the name of the source to be copied and the destination path as to where it is to be copied to.
Sample flat file:... (7 Replies)
Hi,,
Let example cmd: $$config/all
Here I want to replace or subsitute blank space and also with any other character in place of "$" sign...and also want to replace backslash (/) with forward (\)......in expect script
please could any one help on this.....thank you (2 Replies)
Hi,
I have a problem in dollar substitution:-
$ csv1="first_csv"
$ csvnumber=1
$ echo {csv$csvnumber}
{csv1}
$ echo "${csv$csvnumber}"
bad substitution
I want first_csv...why is it not working
thanks (2 Replies)
I was just a-wondering through some hardware and software sites, and in one of them, I was scrolling down a UNIX os page when I noticed that the prices for these OS's were climbing alarmingly high; in the 5 to 10 G's.
Imagine my surprise when I saw one particular UNIX os selling for 65 freakin'... (10 Replies)
I get a transaction file and I need to sum two of the columns. I each record I get a debit(D) or credit(C) indicator. Then I get an amount field. I need to sum the total dollar value of debits and credits.
I know I can loop through each record and get the sum total but is there a better way with... (7 Replies)
All,
How can I get unix to handle the symbol $ as text rather than thinking its a variable value.
e.g When calling a sql script from unix:
exec SQL_PACKAGE('OPS$JOHN.EMP')
where OPS$JOHN is the owner of the table ($JOHN is not a variable!)
Thanks (1 Reply)