小编Iva*_*sov的帖子

如何在Mac OS X上(在iTerm中)将zsh作为登录shell运行?

当zsh在Mac OS X上设置为登录shell时,当它由iTerm启动时,zsh不会认为它是作为登录shell运行的,尽管它以'-zsh'开头(' - '作为arg [0]的第一个字符,它应该意味着它应该作为登录shell启动.

因此,当我将登录shell设置为bash时,bash在$ 0中首先识别出这个' - '并作为登录shell运行,但是zsh不会,尽管它似乎应该.

有没有办法让zsh识别arg [0]中的' - ',或者让iTerm使用--login命令行参数运行shell?

macos bash shell zsh

146
推荐指数
5
解决办法
14万
查看次数

使用`set -u`猛击空数组扩展

我正在写一个bash脚本set -u,我有一个空数组扩展的问题:bash似乎在扩展期间将空数组视为未设置的变量:

$ set -u
$ arr=()
$ echo "foo: '${arr[@]}'"
bash: arr[@]: unbound variable
Run Code Online (Sandbox Code Playgroud)

(declare -a arr也没帮助.)

对此的常见解决方案是使用${arr[@]-}替代,从而替换空字符串而不是("未定义")空数组.然而,这不是一个好的解决方案,因为现在你无法辨别出一个带有一个空字符串的数组和一个空数组.(@ -expansion在bash中是特殊的,它扩展"${arr[@]}""${arr[0]}" "${arr[1]}" …,这使它成为构建命令行的完美工具.)

$ countArgs() { echo $#; }
$ countArgs a b c
3
$ countArgs
0
$ countArgs ""
1
$ brr=("")
$ countArgs "${brr[@]}"
1
$ countArgs "${arr[@]-}"
1
$ countArgs "${arr[@]}"
bash: arr[@]: unbound variable
$ set +u
$ countArgs "${arr[@]}"
0
Run Code Online (Sandbox Code Playgroud)

那么有没有办法解决这个问题,除了检查一个数组的长度if(参见下面的代码示例),或关闭-u该短片的设置? …

bash

89
推荐指数
7
解决办法
1万
查看次数

ARM组装难题

首先,我不确定解决方案是否存在.我花了不少时间试图想出一个,所以要小心.

问题:

r1包含任意整数,根据其值设置标志.如果r1是0x80000000,则将r0设置为1,否则,仅使用两条指令将r0设置为0.

在3条指令中很容易做到这一点(有很多方法),但是在2中这样做似乎很难,而且很可能是不可能的.

puzzle assembly arm bit-manipulation

9
推荐指数
2
解决办法
922
查看次数

shell和命令替换中的“ set -e”

在外壳程序脚本set -e中,当从脚本执行的某些命令以非零退出代码退出时,通常通过停止脚本来使脚本更健壮。

通常很容易指定您不关心|| true最后添加的某些命令是否成功。

当您实际上关心返回值但不希望脚本在非零返回码上停止时,会出现问题,例如:

output=$(possibly-failing-command)
if [ 0 == $? -a -n "$output" ]; then
  ...
else
  ...
fi
Run Code Online (Sandbox Code Playgroud)

在这里,我们既要检查退出代码(因此不能|| true在命令替换表达式内部使用)并获取输出。但是,如果命令替换中的命令失败,则由于导致整个脚本停止set -e

有没有一种干净的方法可以防止脚本在此之前停止而无需取消-e设置然后重新设置呢?

shell robustness

4
推荐指数
1
解决办法
7763
查看次数

当我尝试在同一个管道执行时创建不同的BigQuery表时出错

我使用以下代码执行管道:

PCollection<TableRow> test1 = ...
test1
    .apply(BigQueryIO.Write
        .named("test1 write")
        .to("project_name:dataset_name.test1")
        .withSchema(tableSchema)
        .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
        .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND));

PCollection<TableRow> test2 = ...
test2
    .apply(BigQueryIO.Write
        .named("test2 write")
        .to("project_name:dataset_name.test2")
        .withSchema(tableSchema)
        .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
        .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND));
Run Code Online (Sandbox Code Playgroud)

如果我执行管道并且表"test1"和"test2"都不存在,我将获得以下信息:

jun 09, 2015 12:29:24 PM com.google.cloud.dataflow.sdk.util.BigQueryTableInserter tryCreateTable
INFORMACIÓN: Trying to create BigQuery table: project_name:dataset_name.test1
jun 09, 2015 12:29:27 PM com.google.cloud.dataflow.sdk.util.RetryHttpRequestInitializer$LoggingHttpBackoffUnsuccessfulResponseHandler handleResponse
ADVERTENCIA: Request failed with code 404, will NOT retry: https://www.googleapis.com/bigquery/v2/projects/pragmatic-armor-455/datasets/audit/tables/project_name:dataset_name.test2/insertAll
Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
  "code" : 404,
  "errors" : [ {
    "domain" : "global",
    "message" : …
Run Code Online (Sandbox Code Playgroud)

google-bigquery google-cloud-dataflow

1
推荐指数
1
解决办法
325
查看次数