關於shell切換的問題 - Linux

By Eden
at 2012-03-30T13:04
at 2012-03-30T13:04
Table of Contents
各位好
想請問一下
我有一個test.sh
其中test.sh的第1行有#!/bin/bash來表示我要切換到bash來執行
如果我的shell預設的是/bin/tcsh
用./test.sh #用tcsh shell去執行,執行過程中切換到bash執行
然後再換成 sh ./test.sh #用sh shell去執行,執行過程中切換到bash執行
這兩種方式都是用bash shell去執行程式碼
但是結果卻不一樣...
想請問為什麼會這樣?
我的程式碼如下:
#!/bin/bash
j=0
read -p "number" num
number[$j]="$num"
用sh test.sh 會出現 number[0]=5: not found #可是我第1行有#!/bin/bash...
用./test.sh則執行結果正常 #都是切換到bash 為什麼這一行就正常?
另外想請教的是
似乎tcsh跟sh都不支援這樣的陣列寫法
再網路上看到的幾乎都是bash的寫法
看到這篇
http://yuanann.pixnet.net/blog/post/14988564-shell_script-%3Aarray-
照他的寫法寫也沒辦法用sh執行阿...一樣出現not found
請問有什麼寫法可以支援sh或tcsh呢?
謝謝
--
~宅男的四個徵兆~
∠□ ○ ! * \○/ ★ (○ ?
╦╦└□ " ○□═ □ □>
║║√√ ╦══╦ ∥ |\
一回家就上PTT 每天想正妹 以當好人為樂 忘記正妹虧欠自己
--
想請問一下
我有一個test.sh
其中test.sh的第1行有#!/bin/bash來表示我要切換到bash來執行
如果我的shell預設的是/bin/tcsh
用./test.sh #用tcsh shell去執行,執行過程中切換到bash執行
然後再換成 sh ./test.sh #用sh shell去執行,執行過程中切換到bash執行
這兩種方式都是用bash shell去執行程式碼
但是結果卻不一樣...
想請問為什麼會這樣?
我的程式碼如下:
#!/bin/bash
j=0
read -p "number" num
number[$j]="$num"
用sh test.sh 會出現 number[0]=5: not found #可是我第1行有#!/bin/bash...
用./test.sh則執行結果正常 #都是切換到bash 為什麼這一行就正常?
另外想請教的是
似乎tcsh跟sh都不支援這樣的陣列寫法
再網路上看到的幾乎都是bash的寫法
看到這篇
http://yuanann.pixnet.net/blog/post/14988564-shell_script-%3Aarray-
照他的寫法寫也沒辦法用sh執行阿...一樣出現not found
請問有什麼寫法可以支援sh或tcsh呢?
謝謝
--
~宅男的四個徵兆~
∠□ ○ ! * \○/ ★ (○ ?
╦╦└□ " ○□═ □ □>
║║√√ ╦══╦ ∥ |\
一回家就上PTT 每天想正妹 以當好人為樂 忘記正妹虧欠自己
--
Tags:
Linux
All Comments

By Robert
at 2012-04-01T15:45
at 2012-04-01T15:45

By Regina
at 2012-04-06T00:52
at 2012-04-06T00:52

By Brianna
at 2012-04-07T21:45
at 2012-04-07T21:45

By Isla
at 2012-04-09T07:25
at 2012-04-09T07:25

By Frederica
at 2012-04-12T07:13
at 2012-04-12T07:13

By Doris
at 2012-04-16T13:47
at 2012-04-16T13:47

By Olive
at 2012-04-16T19:31
at 2012-04-16T19:31

By Xanthe
at 2012-04-19T18:46
at 2012-04-19T18:46

By Dinah
at 2012-04-21T10:04
at 2012-04-21T10:04
Related Posts
編譯VLC時出現問題....

By Anonymous
at 2012-03-29T18:11
at 2012-03-29T18:11
瀏覽器影片膚色變藍

By Rosalind
at 2012-03-29T17:34
at 2012-03-29T17:34
pietty 自動送出ctrl-c

By Faithe
at 2012-03-29T14:31
at 2012-03-29T14:31
大家會習慣將linux昇到最新嗎

By Erin
at 2012-03-29T11:00
at 2012-03-29T11:00
Linux耗電

By Carol
at 2012-03-29T06:09
at 2012-03-29T06:09