Linux Bash Shell $*和[email protected]的區別
在 Linux Bash Shell 中,$* 和 [email protected] 都表示引數列表中的所有引數,它們在具體使用中會有哪些不同呢?這裡我們可以寫一個 Shell 指令碼做實驗:
#!/bin/bash
# This script is to verify the difference between $* and [email protected]
echo Dollar Star is $*
echo "Dollar Star in double quotes is $*"
echo Dollar At is [email protected]
echo "Dollar At in double quotes is [email protected]"
echo
echo "Looping through Dollar Star"
for i in $*
do
echo "parameter is $i"
done
echo
echo "Looping through Dollar Star with double quotes"
for i in "$*"
do
echo "Parameter is $i"
done
echo
echo "Looping through Dollar At"
for i in [email protected]
do
echo "Parameter is $i"
done
echo
echo "Looping through Dollar At with double quotes"
for i in " [email protected]"
do
echo "Parameter is $i"
done
檔案儲存為 star.sh,並給予可執行許可權:
# chmod 755 star.sh
然後我們執行以下命令:
# ./star.sh 1 "2 3 " 4 5
結果如下:
Dollar Star is 1 2 3 4 5 Dollar Star in double quotes is 1 2 3 4 5 Dollar At is 1 2 3 4 5 Dollar At in double quotes is 1 2 3 4 5 Looping through Dollar Star parameter is 1 parameter is 2 parameter is 3 parameter is 4 parameter is 5 Looping through Dollar Star with double quotes Parameter is 1 2 3 4 5 Looping through Dollar At Parameter is 1 Parameter is 2 Parameter is 3 Parameter is 4 Parameter is 5 Looping through Dollar At with double quotes Parameter is 1 Parameter is 2 3 Parameter is 4 Parameter is 5
由以上輸出結果可以得出兩者的相同點如下:
1、直接輸出不保留空格
2、帶雙引號輸出會保留帶引號的空格
3、不帶雙引號迴圈遍歷的輸出結果一樣:每個字串單獨輸出
不同點如下:
1、帶雙引號遍歷$*相當於帶雙引號輸出$*
2、帶雙引號遍歷[email protected]分別輸出每個引數,帶雙引號的引數保留空格輸出
相關推薦
Linux Bash Shell $*和<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ffdbbf">[email160;protected]a>的區別
在 Linux Bash Shell 中,$* 和 [email protected] 都表示引數列表中的所有引數,它們在具體使用中會有哪些不同呢?這裡我們可以寫一個 Shell 指令碼做實
linux bash Shell特殊變數:Shell $0, $#, $*, <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8aaeca">[email160;protected]a>, $?
在linux下配置shell引數說明 前面已經講到,變數名只能包含數字、字母和下劃線,因為某些包含其他字元的變數有特殊含義,這樣的變數被稱為特殊變數。 例如,$ 表示當前Shell程序的ID,即pid,看下面的程式碼: [[email protected] /]$ ec
在linux中,$*和<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="90b4d0">[email160;protected]a>有什麼區別?
看了很多的文章,依然似懂非懂。現在,終於理解了它們兩者之間的區別。 $*會把當前指令碼的所有引數作為一個引數傳遞給子指令碼。(在英文中,*字元有“所有”的意思) [email protected]會把當前指令碼的所有引數分別作為一個引數傳遞給子指令碼。(在英文中,@字元有“獨立”的
【Shell】linux bash Shell特殊變數:Shell $0, $#, $*, <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4f6b0f">[email160;protected]<
在linux下配置shell引數說明 前面已經講到,變數名只能包含數字、字母和下劃線,因為某些包含其他字元的變數有特殊含義,這樣的變數被稱為特殊變數。 例如,$ 表示當前Shell程序的ID,即pid,看下面的程式碼: $echo $$ 執行結果 29949
在linux中,$*和<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="250165">[email160;protected]a>有什麼區別?
看了很多的相關文章,似懂非懂。現在,終於真正理解了它們兩者之間的區別。 首先我們看如下一個bash命令: ./start.sh "a b" "c" "d" 請問,給start.sh指令碼傳遞了幾個引數? 大部分人都知道,總共傳遞了3個引數,其中,$1等於a b,$2等
【linux備忘筆記】Linux root 從bash-3.2回到<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8af8e5e5fecae6e5e9ebe6e2e5f9fe">[email160;
1.進入目錄 cd /etc/skel 2.顯示隱藏檔案 ls -a .bash_logout .bash_profile .bashrc 拷貝這些隱藏檔案到/home 接
linux <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="311571">[email160;protected]a>和$*區別
最近學習shell程式設計,發現 [email protected]和$*很有意思,分享一下 $* 取當前shell的所有引數,將所有的命令列視為單個字串,相當於“$1$2” [email protected] 取當前shell的所有引數保留引數裡的空白
[Happy BASH] BASH中的$*和<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="426602">[email160;protected]a>的區別
首先來看一段BASH程式碼: echo "\[email protected]=" [email protected] echo "\"\[email protected]\"=" "[email protected]" echo
Springboot註解<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="260b0b666549485254494a4a4354">[email160;protected]a>和@RestCon
1.使用@Controller 註解,在對應的方法上,檢視解析器可以解析return 的jsp,html頁面,並且跳轉到相應頁面;若返回json等內容到頁面,則需要加@ResponseBody註解 [email protected]註解,相當於@[email protected
面試題:一個字串包含英文和特殊字元,特殊字元不變,英文順序反過來,比如string str="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b4d0a4f5c6b">[email160
public class Reverse { public static void main(String[] args) { String str = "[email protected]!tk"; char[] chars = str.toCh
python基礎<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="775a5a37141b1604041a12031f1813">[email160;protected]a>和@staticmet
Python中3種方式定義類方法, 常規方式, @classmethod修飾方式, @staticmethod修飾方式. class A(object): def foo(self, x): print("executing foo(%s,%s)" % (self, x)
spring宣告式事務管理方式( 基於tx和aop名字空間的xml配置<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0922495d7b68677a686a7d6066676865">[email
轉自:https://www.cnblogs.com/niceyoo/p/8732891.html 1. 宣告式事務管理分類 宣告式事務管理也有兩種常用的方式, 一種是基於tx和aop名字空間的xml配置檔案,另一種就是基於@Transactional註解。 顯然基於註解的方式更簡單
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c384aab7838c9080">[email160;protected]a>伺服器和Xcode的git管理工具簡單使用
OSChina提供的git伺服器,每一個賬號可建立1000個專案,不論公有或私有專案,程式碼託管服務永久免費。而且由於是國內的網站和伺服器,又是中文的,相對於國外的而言,訪問比較通暢,操作起來也容易上手。 本文介紹如何使用OSChina的g
Centos7 中[<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b7c5d8d8c3f7dbd8d4d6dbdfd8c4c3">[email160;protected]a> /] 和 [
1. [[email protected] /] 和 [[email protected] ~] 的區別 剛進入Centos時, 會顯示這個[[[email protected] ~] , 後邊讓輸入命令, 其實此時是在
verilog中assign和<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3859544f59414b78">[email160;protected]a>(*)兩者描述組合邏輯時的差別
verilog描述組合邏輯一般常用的有兩種:assign賦值語句和[email protected](*)語句。兩者之間的差別有: 1.被assign賦值的訊號定義為wire型,被[email protected](*)結構塊下的訊號定義為reg
Linux下$#,$0,$1,$2,$3,<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bc98fc">[email160;protected]a>,$*,$$,$?代表的含義
$# :傳給指令碼的引數個數; $0 :指令碼名稱; $n :n為數字,代表傳給指令碼的第n個引數; [email protected] :引數列表; $* :也是顯示引數列表,與上一條命
@<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9edfebeaf1e9f7ecfbfadecfebfff2f7f8f7fbec">[email160;protected]a>和@Resour
@Autowired:是Spring自己定義的註解。@Autowired按byType自動注入。注入系統型別不會有type相同的多個類問題。當自定義了多個type相同,名稱不同的類時使用@Qualifier進行限定。@Qualifier預設限定的是name。使用@Qualifier需要在配置檔案&l
Spring 註解例項<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="82afafc2c3f7f6edf5ebf0e7e6">[email160;protected]a> 注入到List和Map
package com.Autowired.ListMap; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; /** *
AngularJs註解之<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b598989898f5dcdbc5c0c1">[email160;protected]a>和@output
從翻譯的角度看 input---輸入 output---輸出 所以:這兩個註解的意思是:對父元件傳入的引數的接收,和對結果傳入到父元件中 程式碼奉上: 父元件中的傳參 &nb
淺談linux中shell變數$#,<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="674327">[email160;protected]a>,$0,$1,$2,$?的含義解釋
淺談linux中shell變數$#,[email protected],$0,$1,$2,$?的含義解釋 下面小編就為大家帶來一篇淺談linux中shell變數$#,[email protected],$0,$1,$2的含義解釋。小編覺得挺不錯的,現在就分享給大家,