- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
如何在 csh 的 if else 语句中传递失败脚本的退出代码?例如
if ( "test" != "test" ) then
/bin/true
else
/bin/false
endif
echo $?
给出0的退出代码。但是只是运行
/bin/false
echo $?
给出退出代码 1。
似乎 endif 只是覆盖了 if else 语句中命令输出的退出代码。
endif
echo $?
退出代码:0
除了在运行每个命令后将其设置为变量之外,是否有更好的方法从语句中传递退出代码?
例如
if ( "test" != "test" ) then
/bin/true
set exitcode = $?
else
/bin/false
set exitcode = $?
endif
/bin/false 和/bin/true 只是这些位置的脚本示例,要么失败要么成功,以及 endif 如何覆盖它们的退出代码。因此,这些语句中的任何一个的退出代码都可以是任何 [0-255]。我不是要捕捉简单的 1 或 0。
更新
如果您创建一个 csh 脚本,Thomas 的以下建议似乎可行。
#!/bin/csh
if ( "test" != "test" ) then
/bin/true
exit $?
else
/bin/false
exit $?
endif
但是如果用ssh的话好像不行
ssh -A -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $USER@`hostname` '
>if ( "test" != "test" ) then
> /bin/true
> exit $?
>else
> /bin/false
> exit $?
>endif'
echo $?
0
最佳答案
你可以只使用退出:
#!/bin/csh
if ( "test" != "test" ) then
/bin/true
exit $?
else
/bin/false
exit $?
endif
exit可以处理1byte的退出码[0-255]
关于Linux 如果 csh 中有退出代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48944581/
我有这个非常简单的 csh 脚本。 #!/bin/csh echo "Hello World!" echo "How are you today?" 但我收到错误“:未
简短的 我如何 (1) 启动一个新的 csh,(2) 强制它执行一些不在任何 .cshrc 中的命令(尽管我可以将它们安排在非标准位置以获取源)和(3)然后去互动? 例如。除了在 http://www
我想获取多个目录中所有 ofl 类型文件的列表。我使用了以下命令: ls RESULTS/*/quakesim/iecrud/quake/fgb/stflt/*.ofl 但我收到一条消息:/bin/l
例如,我想用逗号作为分隔符分割“一,二,三”,并使用循环分别处理结果的三个子字符串。 最佳答案 比当前提出的解决方案更简单的解决方案涉及使用内置替换修饰符 - 在这种情况下没有必要或理由浪费地使用循环
我想获取多个目录中所有 ofl 类型文件的列表。我使用了以下命令: ls RESULTS/*/quakesim/iecrud/quake/fgb/stflt/*.ofl 但我收到一条消息:/bin/l
我确实有一个需要 csh 的工具,但我的默认 shell 是 bash。我想要/需要在 csh 中从 bash 执行或获取 csh 脚本,并且我想在脚本执行后以 csh 提示结束。 从 bash 我可
我有以下非常简单的代码: #!/usr/bin/env csh set status=0 if ( 0 == 0 ) then ls ./dummyDir set status=$?
我有一个脚本,用于在调用 csh shell 中设置一些环境变量。其中一些变量取决于脚本的位置。 如果该文件是正确的 csh 脚本,我可以使用 $0 访问 __FILE__但如果我使用源代码运行脚本,
在 bash 中,我可以为一个命令设置一个临时环境变量,如下所示: LD_LIBRARY_PATH=/foo/bar myprogram 我可以在 csh/tcsh 中做类似的事情吗?我可以做 set
csh 是一个极其可怕的 shell。 (预先声明以避免不可避免地出现“不要使用 csh”的评论,或者也许我应该为了任何读者而声明:请,如果您重视自己的理智,请不要使用 csh。)我有一个相当大的 c
在 bash 中,我使用 Ctrl + w 来执行此操作,但它在我的 csh 中不起作用,它不是删除一个单词,而是清理整行。如何删除最后一个单词? 尽管 Ctrl + u 在 csh 和 bash 中
我有一个文件,其中包含以下命令。 #!/bin/csh -f echo "test test" //echo test [dobule space] test set a = "test tes
我有一个执行以下操作的小脚本。我已经为这个例子简化了它。 set logfile=$HOME/LOG/output.log find execute.sh -type f -exec csh -c '
我知道csh有很多启动文件(.login、.cshrc等)。问题是我正在启动一个新的 csh 终端,我看到很多非标准的(不是标准的,如 $HOME、$SHELL 等)在启动时设置的我没有的环境变量在我
我需要将 argv 中的部分内容连接到我的变量之一。 我将向您展示我的代码: #!/bin/csh set stringList = "" foreach param ($argv) if($
我想在 tcsh 中使用变量来保存脚本的使用信息,因此在我的脚本中,每当我编写 echo $usage 时,它都会打印 my_script -h : -help -b : do boo 等
如果两个文件没有区别,我想检查如何打印成功消息。 例子 diff file1 file2 最佳答案 shell 环境 $? 给出最后一条命令的结果。如果文件匹配则为 0,如果文件不同则为非 0。 di
我已经知道我可以使用参数-l来启动bash或ksh作为登录shell,所以我不不必获取诸如 ~/.profile、~/.bash_profile 等文件。但是在csh中,这句话 execl("/bin
如果输入日期具有以下格式,是否有办法将输入日期与当前日期进行比较? 2015 年 10 月 10 日星期六 00:00:55 现在我正在检查月份是否不在 NOV, DEC 中并且年份是否仍然是 201
如何计算字符串中的特定字符 - CSH。 set my_path = "/home/user/docs/files" set sum = ??? 比方说,我们需要计算'/' 最佳答案 如果你不能使用任
我是一名优秀的程序员,十分优秀!