
나는 다음 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
확실히 배쉬인가요? 백틱 연산자는 이식 가능하지 않습니다. 이 문제를 해결하는 방법에는 여러 가지가 있습니다.
#!/bin/bash
bash가 아닌 다른 것이 없도록 첫 번째 줄에서 사용하십시오 .- 백틱을 피하십시오:
currentdir=$(pwd)
또는currentdir=$(/bin/pwd)
- 아니면 더 간단하게
currentdir=$PWD