我有一個格式爲「Thu Sep 22 3:50 2016」的日期,我想將它轉換爲格式:「2016-09-22 「轉換日期字符串到Solaris shell腳本上的編號給出沒有這樣的文件或目錄
我試過下面的shell腳本,它對'date'工作正常,但給用戶指定的字符串提供了錯誤:(我正在使用Solaris平臺)。任何投入都將有所幫助。
輸入:
#!/usr/bin/sh
mydate="Thu Sep 22 3:50 2016"
echo `date +"%Y-%m-%d"`
echo `$mydate +"%Y-%m-%d"`
輸出
./testShell.sh
**2016-09-22**
./testShell.sh[6]:Thu: not found **[No such file or directory]**
任何指針嗎?
您正在使用哪種Solaris版本? 'cat/etc/release' – jlliagre
PS。現在被刪除的答案依賴於GNU date',這在Solaris上不一定可用。 – jlliagre
謝謝你指出。可否請您提出建議,那麼將「Thu Sep 22 3:50 2016」轉換爲「2016-09-22」的最佳方法是什麼?可能是我也應該編輯我的問題 – user2306856