[20200214]xargs與別名.txt
[20200214]xargs與別名.txt
--//上午在最佳化sql語句時,發現xargs與alias的程式存在一點點小問題,做一個記錄。
$ alias rrlsql='rlwrap sqlplus '
$ rrlsql -s -l scott/book @ ver1 <<< ' '
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
$ echo @ver1 | xargs -I{} rrlsql scott/book {}
xargs: rrlsql: No such file or directory
--//也就是xargs不支援別名,應該是另外開一個shell,裡面的環境與登入的bash shell環境不一致。
$ echo @ver1 | xargs -I{} sqlplus -s -l scott/book {}
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
$ alias ls
alias ls='ls --color=auto --time-style=+"%Y-%m-%d %H:%M:%S"'
$ echo bb1.txt | xargs ls -l
-rw-r--r-- 1 oracle oinstall 230 Feb 12 16:03 bb1.txt
$ ls -l bb1.txt
-rw-r--r-- 1 oracle oinstall 230 2020-02-12 16:03:45 bb1.txt
--//注意我顯示的日期格式,執行時並沒有現在別名ls。
$ echo bb1.txt | xargs -IQ bash -c 'ls -l Q'
-rw-r--r-- 1 oracle oinstall 230 Feb 12 16:03 bb1.txt
--//不行。
$ echo bb1.txt | xargs -IQ bash -ic 'ls -l Q'
-rw-r--r-- 1 oracle oinstall 230 2020-02-12 16:03:45 bb1.txt
Aliases are shell-specific - in this case, most likely bash-specific. To execute an alias, you need to execute bash, but
aliases are only loaded for interactive shells (more precisely, .bashrc will only be read for an interactive shell).
bash -i runs an interactive shell (and sources .bashrc). bash -c cmd runs cmd.
--//我必須講別名放入.bashrc檔案中,重新登入開啟新的終端:
--//加入如下.bashrc.
alias rrlsql='rlwrap sqlplus '
$ echo @ver1 | xargs -IQ bash -ci 'rrlsql -s -l scott/book Q'
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
--//OK!!
--//在測試中我還遇到一個問題。
$ echo 4xamnunv51w9j | xargs -IQ bash -ci rrlsql -s -l scott/book @dpc Q ''
SQL*Plus: Release 11.2.0.4.0 Production on Fri Feb 14 16:07:46 2020
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Enter user-name:
--//必須加雙引號才OK。
$ echo 4xamnunv51w9j | xargs -IQ bash -ci "rrlsql -s -l scott/book @dpc Q ''"
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 4xamnunv51w9j, child number 0
-------------------------------------
select * from dept where deptno=10
Plan hash value: 2852011669
----------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 1 (100)| |
| 1 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | 20 | 1 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | PK_DEPT | 1 | | 0 (0)| |
----------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / DEPT@SEL$1
2 - SEL$1 / DEPT@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("DEPTNO"=10)
Note
-----
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
31 rows selected.
argment : typical all advanced partition predicate remote note parallel projection alias peeked_binds outline adaptive
--//另外的問題:
--//我的rlsql定義的是函式
$ echo 4xamnunv51w9j | xargs -IQ rlsql -s -l scott/book @dpc Q ''
Enter value for 2:
SP2-0546: User requested Interrupt or EOF detected.
argment : typical all advanced partition predicate remote note parallel projection alias peeked_binds outline adaptive
--//最後1個引數''無法解析,加入引號或者\轉義可以透過。
$ echo 4xamnunv51w9j | xargs -IQ rlsql -s -l scott/book @dpc Q "''"
$ echo 4xamnunv51w9j | xargs -IQ rlsql -s -l scott/book @dpc Q \'\'
$ echo 4xamnunv51w9j | xargs -IQ rlsql -s -l scott/book @dpc Q all
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2675611/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20210218]xargs 與here doc測試.txt
- xargs 命令詳解,xargs 與管道的區別
- [20210322]seq xargs.txt
- [20200417]xdate別名.txt
- [20191128]date命令別名.txt
- [20211213]完善date命令別名.txt
- [20220311]windwos下使用seq與xargs建立多個子目錄問題.txt
- [20190219]xargs -P實現並行執行.txt並行
- [20220329]windwos下使用seq與xargs建立多個子目錄問題(補充).txt
- linux 命令值xargs與trLinux
- [20211123]sqlplus @與@@的區別.txtSQL
- [20180702]物件名重用.txt物件
- 蘋果企業簽名與其他簽名區別與好處蘋果
- xargs 命令教程
- Windows修改新建.txt檔名Windows
- [20220329]批量修改檔名.txt
- [Bash] Backticks, xargs and Arithmetic
- [2020528]寫sql語句不要忘記給欄位加上表別名.txtSQL
- [20230425]注意snapshot standby與activate standby的區別.txt
- 在Linux中,如何使用xargs和exec實現把當前目錄下所有字尾名為.txt的⽂件的許可權修改為777。Linux
- JavaScript 節點物件的型別與名稱JavaScript物件型別
- yii別名的定義和別名的獲取以及別名的使用
- Linux xargs命令介紹Linux
- What does "xargs grep" do?
- Linux xargs 命令詳解Linux
- Linux命令(1)——xargs命令Linux
- [20211020]XXXX_DGB服務名.txt
- 模板別名
- 物件導向與函數語言程式設計的區別: 動詞-名詞與名詞-動詞的區別 - simblob物件函數程式設計
- TypeScript type 型別別名TypeScript型別
- [20200214]Printing all table preferences affecting dbms_stats.gather_table_stats
- [20200109]主機名如何定位IP.txt
- [20191219]索引名裡帶回車符.txt索引
- 小知識:講述Linux命令別名與資原始檔的區別Linux
- 電子簽名與手寫簽名的區別,電子簽名的優勢是什麼?
- 程式碼簽名證書與SSL證書區別
- 007 Rust死靈書筆記之引用與別名Rust筆記
- Elasticsearch之索引模板index template與索引別名index aliasElasticsearch索引Index