问题标签 [dash-shell]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
if-statement - 破折号中预期“完成”的意外“然后”:如何在破折号的 for 循环中插入 if 条件?
我正在使用破折号,我需要创建将解析查询字符串并将每个值保存到变量的 CGI 脚本
我确定我在获取行(或字符串)的子字符串时出错,但请让我们关注我在 for 循环中放置 if 语句时遇到的错误。在破折号 shell 脚本中,在 for 循环中编写 if 条件的正确方法是什么。
附加信息,我使用的是 ubuntu 14.04,
regex - 跨多个 shell 的正则表达式兼容性
我正在使用以下代码在我的 bash 脚本中检查正确的日期格式:
格式应为:YYYY-MM-DD
这在 bash 中运行良好,但是当我尝试在 dash 或 sh 中运行它时遇到问题。你能帮我重写一下,使它与 dash 和 sh 兼容吗?或者找到一个可以在所有外壳上使用的不同解决方案?
提前致谢 !
bash - [ x"$1" != x"" ] 的目的是什么?
目的是[ x"$1" != x"" ]
什么?
查看 xdg-screensaver,运行的第一个命令:
shebang 是#!/bin/sh
(这对我来说是破折号)。
我在其他旧的 shell 脚本中发现了类似的语法……这样做的目的是什么?
我想有一个旧习惯使用|| 而不是 && 退出...也许与set -e
. 但是为什么不直接使用类似[ -n "$1" ] || exit_failure_syntax
, -z
, $# -ne 0
, 等等...
正如我所提到的,我以前见过这种奇怪的x"$var" = x""
东西。为什么会有人这样做?
shell - 为什么“破折号-c':'”会因从源代码构建的破折号0.5.8而失败?
使用从源代码编译的 dash 二进制文件(版本 0.5.8,可在http://gondor.apana.org.au/~herbert/dash/files/dash-0.5.8.tar.gz获得),执行
失败了
这意味着诸如
失败,这破坏了很多脚本。为什么用ubuntu分发的dash二进制没有这个问题?
bash - shell:通配符能保证字母顺序吗?
当我有文件a.txt
时b.txt
,c.txt
是否可以保证
或者
将按字母顺序组合文件?
(在我所有的测试中,字母顺序都被保留了,但我不确定,因为例如ls
顺序是未定义的,不需要是字母顺序 - 但通常是,因为文件经常按字母顺序写入目录)
loops - 如何限制侦听文件系统更改的破折号循环的 CPU 使用率?
我在 dash 中写了一个循环,等待文件出现在文件系统的某个位置。但是当它运行时,它会占用 50% 的 CPU。我首先使用 sleep 命令降低了 CPU 使用率,但是短划线中的最短睡眠时间(1 秒)对我来说太长了。
我需要一种在 bash 中睡眠时间少于 1 秒的方法,或者需要一种不同的解决方案来降低循环的 CPU 使用率。我只想使用大多数 unix 系统上默认安装的程序。
bash - 在 shell 脚本中可移植地捕获 ERR
我正在尝试编写一个 shell 脚本,该脚本在命令失败时中止并显示有问题的行号。
原来陷阱行不适用于 Ubuntu 的默认 shell 脚本解释器破折号。如果我将 shebang 线更改#!/bin/bash
为此工作,但不使用#!/bin/sh
. 有没有办法在不依赖 bash 存在的情况下完成这项工作?
顺便说一句,我从破折号得到的错误是:
bash - Makefile multiline dash command run executable in a detached process
I have the following target in my makefile: (I'd like to run python http server in a detached process and when bash script is done kill the server)
However when I put a &
after the line python ...
I get an error
/bin/dash: Syntax error: ";" unexpected
How can this be done in a proper way?
EDIT
I have changed my makefile to do the following:
However I am getting an error: (without the line number)
/bin/dash: Syntax error: word unexpected
bash - 为什么 read 在 bash 和 dash 中的行为不同?
这是试图找出 read 实用程序在多个 shell 中是如何工作的。发现了一个对我来说似乎是错误的差异。
结果是破折号保留带有读取的尾随空格:
简而言之:为什么这段代码在 bash 和 dash 读取中的表现不同?
unix - 带有`set -e`和子shell的sh中的奇怪行为
Continuing
如果我删除子外壳,下面的代码会打印出来。:
使用 subshell ,如果我想进入该Continuing
部分,我需要在测试后再次成功调用(使用成功的 no-op 命令是最直接的,IMO)。
这种行为正确吗?为什么引入子shell会改变
我正在使用dash 0.5.7-2ubuntu2
来运行它。