English 中文(简体)
如何在......是否精炼结构的情况下评估巴什指挥系统的撤出状况?
原标题:How to evaluate the exit status of bash command in if ... elif structure?

我说,用印本做是新鲜事,但我不敢肯定如何做。 我有一个指挥,试图在具体的道路上安装一个磁盘。 综合安全分遣队1被定义为在某个特定USB港口进行特别的SSD驱使——这里并不重要。

/bin/mount DISK1 ${MOUNT_PATH}

我现在要检查这一增长是否成功。 通常,如果这一表述成功的话,它就会回去,但一旦出现错误,表达就会回去32。

if [$? -eq 0]; then
   echo "Mounted DISK 1 at ${MOUNT_PATH}"
elif [$? -eq 32]; then
   echo "DISK 1 read error"
else
   echo "FAILED TO MOUNT"
fi

When this script ran, and the expression came back as 32, it went to the elif block, but then I got a "command not found" for this. I assume that because "$?" had already been evaluated, so you can t call "$?" again?

So how would you get it to run the mount expression evaluation again and do a 32 -eq 32 comparison so that it can run the "DISK 1 read error"?

储存评价是解决这一问题的方法吗? 该法典是否可行? 由于磁盘重读错误需要几天才能显示,我很难测试该代码。

/bin/mount DISK1 ${MOUNT_PATH}
$mnt_stat = $?
if [$mnt_stat -eq 0]; then
  echo "Mounted DISK 1 at ${MOUNT_PATH}"
elif [$mnt_stat -eq 32]; then
  echo "DISK 1 read error"
else
  echo "FAILED TO MOUNT"
fi
最佳回答
问题回答

除了一些辛塔克斯错误(在<代码>上没有位置[和][和>上下)和错误的派任之外,你还处于正确的轨道上:

Would storing the evaluation be the way to approach this?

是的,由于<代码>[>(aka test)的每项执行都制定了$?,因此,在第一个>>>>>后,你失去<代码>>>/代码>的指挥结果。 发言<代码>[

1. 贵国法典的最低限度修改文本是:

/bin/mount DISK1 "${MOUNT_PATH}"
# (exit 32)  # Uncomment to fake a return value.
mnt_stat=$?  # Save return code (no $ sigil before mnt_stat or spaces around the = here).
if [ $mnt_stat -eq 0 ]; then  # Add spaces around [ and ], but ; doesn t need a space.
  echo "Mounted DISK 1 at ${MOUNT_PATH}"
elif [ $mnt_stat -eq 32 ]; then
  echo "DISK 1 read error"
else
  echo "FAILED TO MOUNT"
fi




相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签