问题:

在我的脚本中,我尝试对第一个也是唯一的参数是否等于-v进行错误检查,但这是可选参数。 我使用if语句,但始终收到一元运算符预期的错误。

这是代码:

if [ $1 != -v ]; then
   echo "usage: $0 [-v]"
   exit
fi

编辑:

我应该更具体一些:上面脚本的这一部分正在检查可选参数,然后,如果未输入该参数,则它将运行程序的其余部分。

#!/bin/bash

if [ "$#" -gt "1" ]; then
   echo "usage: $0 [-v]"
   exit
fi

if [ "$1" != -v ]; then
   echo "usage: $0 [-v]"
   exit
fi

if [ "$1" = -v ]; then
   echo "`ps -ef | grep -v '\['`"
else
   echo "`ps -ef | grep '\[' | grep root`"
fi

In my script I am trying to error check if the first and only argument is equal to -v but it is an optional argument.I use an if statement but I keep getting the unary operator expected error.this is the code:Edit:I should be more specific: This part of the script above is checking an optional argument and then after, if the argument is not entered, it should run the rest of the program.

问题:

原谅我,这是Bash中非常简单的脚本。 这是代码:

#!/bin/bash
# june 2011

if [ $# -lt 3 -o $# -gt 3 ]; then
   echo "Error... Usage: $0 host database username"
   exit 0
fi

运行sh file.sh之后:

语法错误:文件意外结束

Forgive me for this is a very simple script in Bash.Here’s the code:after running sh file.sh:syntax error: unexpected end of file

问题:

这个问题已经在这里有了答案:

做一些流编辑以更改讨厌的Parallels图标。 它开发不良,无法嵌入到应用本身中,而不是图像文件。 因此,我找到了这个sed命令,它具有一些良好的反馈:

sudo sed -i.bak s/Parallels_Desktop_Overlay_128/Parallels_Desktop_Overlay_000/g /Applications/Parallels\ Desktop.app/Contents/MacOS/prl_client_app

它返回sed: RE error: illegal byte sequence

谁能解释这意味着什么? 问题出在命令的哪一部分?

This question already has an answer here:RE error: illegal byte sequence on Mac OS X 7 answersDoing some stream editing to change the nasty Parallels icon.It’s poorly developed and embedded into the app itself rather than being an image file.So I’ve located this sed command that has some good feedback:It returns sed: RE error: illegal byte sequenceCan anyone explain what this means?What part of the command is the problem?

问题:

它可以作为单个工具正常工作:

curl "someURL"
curl -o - "someURL"

但它在管道中不起作用:

curl "someURL" | tr -d '\n'
curl -o - "someURL" | tr -d '\n'

它返回:

(23) Failed writing body

用管道传输cURL输出有什么问题? 如何缓冲整个cURL输出然后处理它?

It works ok as a single tool:but it doesn’t work in a pipeline:it returns:What is the problem with piping the cURL output?How to buffer the whole cURL output and then handle it?

问题:

我在脚本中这样做:

read direc <<< $(basename `pwd`)

我得到:

Syntax error: redirection unexpected

在ubuntu机器上

/bin/bash --version
GNU bash, version 4.0.33(1)-release (x86_64-pc-linux-gnu)

虽然我没有在另一台suse机器上得到这个错误:

/bin/bash --version
GNU bash, version 3.2.39(1)-release (x86_64-suse-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

为什么错误?

I do this in a script:and I get:in an ubuntu machinewhile I do not get this error in another suse machine:Why the error?