1. 程式人生 > >linux--shell錯誤:syntax error near unexpected token ‘('

linux--shell錯誤:syntax error near unexpected token ‘('

這幾天編寫了幾個簡單的shell程式,然後都出現了syntax error near unexpected token ‘('

的錯誤,然後實在是檢查不出錯誤;後面百度了才找到的原因:

之前錯誤的程式片段如下:

usr=$ (whoami)

dr=$ (pwd)

提示的錯誤如下:

syntax error near unexpected token ‘('

後面才知道原來是$ 與左括號之間多了一個空格,改正以後程式就正常運行了。

其實上面usr=$(whoami)等價於 usr=`whoami`

相關推薦

linux--shell錯誤syntax error near unexpected token ‘('

這幾天編寫了幾個簡單的shell程式,然後都出現了syntax error near unexpected token ‘(' 的錯誤,然後實在是檢查不出錯誤;後面百度了才找到的原因: 之前錯誤的程式

shell編程報錯syntax error near unexpected token `”

一個 兩個 tle ctrl+v center 以及 中修改 blank 存儲 shell編程報錯:“syntax error near unexpected token `” 今天寫了個shell腳本,在自己機器上運行正常,給同事,運行報錯syntax error nea

shell程式設計報錯syntax error near unexpected token `”

在UE下使用16進位制看了一下,是0D0A結尾的,修改為OA結尾的。使用b.cat filename1 | tr -d "\r" http://blog.csdn.net/xyp84/article/details/4435899   今天寫了個shell指令碼,

執行shell指令碼提示“syntax error near unexpected token for((i=0;i

sh指令碼如下: #!/usr/bin/env bash county="3 4 5 6 7 8 9 10 11 12 16 29 39 44 53 62 72 84 97 115 128 151

指令碼報錯syntax error near unexpected token

今天將之前寫好的shell指令碼拿出來用,發現執行時就報錯:syntax error near unexpected token 很奇怪,之前執行的一直沒事... 後來在網上找了下,發現指令碼內容每行尾行都添加了^M的字元,檢視方式:vi -b 開啟指令碼檔案 後

shellsyntax error near unexpected token `fi'錯誤

一、原始碼 #! /bin/bash   if [ $# -eq 0 ] then echo  "$0 filename" exit fi   if [ $# = 1 ] then if ! [ -c $1 ] th

linux下解決rm 反向刪除報錯syntax error near unexpected token `('的問題

程式碼: #!/bin/bash service csrasm stop sleep 5 service csrass stop sleep 10 cd /etc/csrass rm -fr !(csrass.srd) service csrasm start service csrass star

shell程式設計 報錯 syntax error near unexpected token 最終解決

剛接觸shell程式設計,問題不斷,這個問題有兩種情況: 第一種是像網上說的那些,因為換行符的問題,其產生的通常情況是你在Windows下編寫好的程式碼,放到linux下執行出錯,如果是此種情況,請移步網上方法解決,這裡不再贅述。 下面說我遇到的第二種情況,其實這種問題出

bash: syntax error near unexpected token `newline'(關鍵詞flask/bug)

《Flask Web開發》第6章 電子郵件 使用Flask-Mail提供電子郵件支援,P60: (venv) $ export MAIL_USERNAME=<Gmail username>

-bash:syntax error near unexpected token '('

xshell5 shel 括號 ted bash 出錯 linu linux5 ear 在Xshell5中編寫int main(int argc,char** argv)時, 出現-bash:syntax error near unexpected token ‘(‘ ;

mac下-bash: syntax error near unexpected token `('

在使用go-xorm將mysql的表結構匯出為go 結構體時候,出現如下錯誤 $ xorm reverse mysql root:[email protected](127.0.0.1:3306)/dbname?charset=utf8 templates/goxorm/ -bash:

[Bash]syntax error near unexpected token 'then'

#!/bin/bash clear function test { if[$1 -eq "root"]&&[$2 -eq "123456"] then echo "Right" else echo

bash: ./xxxx.sh: line xx: syntax error near unexpected token "xx''

今天在編譯android openssl的時候使用指令碼檔案出現了下面的錯誤: [email protected]:~/AndroidBox/openssl-1.1.0f$ source ./setenv-android.sh : command not fou

syntax error near unexpected token `(' 問題解決方法

 #!/bin/bash  #Program: # #History: #2018/11/10 LY first release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin

syntax error near unexpected token `do

這種情況發生的原因是因為你所處理的檔案換行符是dos格式的"\r\n"可以使用cat -v 檔名來檢視換行符是否是。如果是上述的,則行結尾會是^m,需要轉換成linux/unix格式的"\n"。#!/b

關於報錯“syntax error near unexpected token `”和回車換行

本來是很簡單一個事情,轉過來是因為打字機這事比較有趣…… http://blog.csdn.net/xyp84/archive/2009/08/11/4435899.aspx 摘要一下: 回車 換行 0D 0A <CR> <LF&

syntax error near unexpected token `newline'指令碼無法執行

問題描述 執行run.sh指令碼是報錯,報錯資訊如下: /data/app/information-provider : No such file or directory : command not found ./run.sh: line 4: sy

syntax error near unexpected token `$' ''

查看 bsp access ces 換行 syn 就是 nta sed 這種情況發生的原因是因為你所處理的文件換行符是dos格式的"\r\n"可以使用cat -v 文件名 來查看換行符是否是,如果是上述的,則行結尾會是^m需要轉換成linux/unix格式的"\n"具體轉換

shell指令碼Syntax error: Bad for loop variable錯誤解決方法

Linux Mint中寫了一個簡單的shell指令碼,利用for..do..done結構計算1+2+3......+100的值,結果執行"sh -n xxx.sh"檢測語法時總是報錯,但在PC機上可正

ajax請求,fastjson報出錯誤syntax error, expect {, actual error, pos 0

報錯資訊如下: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: syntax error, expect [, actual error, pos 0, fieldNa