
我有以下 Sun Grid Engine 提交腳本:
#!/bin/sh
# sun grid engine cluster
# use current working directory
#$ -cwd
# merge error output into standard output stream
#$ -j yes
#$ -o generate_databases.log
# request to cpu number
#$ -pe make 4
currentdir=`/bin/pwd`
echo "current working directory: $currentdir"
這是我的輸出
/home/eamorr/sge
currentdir: Undefined variable.
如您所見,“currentdir”變數傳回未定義。
如何解決這個問題?
答案1
你確定這是bash嗎?反引號運算子不可移植。有幾種方法可以(可能)解決這個問題:
- 在第一行中使用
#!/bin/bash
以確保它是 bash 而不是其他任何東西 - 避免反引號:
currentdir=$(pwd)
或currentdir=$(/bin/pwd)
- 甚至更簡單
currentdir=$PWD