相关疑难解决方法(0)

Bash中是否有TRY CATCH命令

我正在编写一个shell脚本,需要检查是否已安装终端应用程序.我想使用TRY/CATCH命令来执行此操作,除非有更简洁的方法.

error-handling bash shell

280
推荐指数
10
解决办法
24万
查看次数

shell脚本是否对编码和行结尾敏感?

我正在Mac上制作NW.js应用程序,并希望通过双击图标以开发模式运行应用程序.第一步,我正在尝试使我的shell脚本工作.

在Windows上使用VSCode(我想获得时间),我run-nw在项目的根目录创建了一个文件,其中包含:

#!/bin/bash

cd "src"
npm install

cd ..
./tools/nwjs-sdk-v0.17.3-osx-x64/nwjs.app/Contents/MacOS/nwjs "src" &
Run Code Online (Sandbox Code Playgroud)

但我得到这个输出:

$ sh ./run-nw

: command not found  
: No such file or directory  
: command not found  
: No such file or directory  

Usage: npm <command>

where <command> is one of:  (snip commands list)

(snip npm help)

npm@3.10.3 /usr/local/lib/node_modules/npm  
: command not found  
: No such file or directory  
: command not found
Run Code Online (Sandbox Code Playgroud)

我真的不明白:

  • 似乎它需要空行作为命令.在我的编辑器(VSCode)我试图替换\r\n\n(以防\r造成了问题),但它改变不了什么.
  • 它似乎找不到文件夹(有或没有dirname指令),或者它可能不知道cd …

bash shell sh

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

循环Linux Shell的空身体

嗨,我想写和空身体循环.我只是想让循环计数器递增,所以我希望cpu在没有任何IO操作的情况下保持忙碌状态.这是我写的,但它给了我一个错误:

#!/bin/bash
for ((  i = 0 ;  i <= 1000000;  i++  ))
do
done


root@ubuntu:~# ./forLoop
./forLoop: line 4: syntax error near unexpected token `done'
./forLoop: line 4: `done'
Run Code Online (Sandbox Code Playgroud)

linux shell ubuntu loops

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

意外令牌"完成"附近的语法错误令人困惑

我正在尝试学习shell脚本,所以我创建了一个简单的脚本,其循环不执行任何操作:

#!/bin/bash
names=(test test2 test3 test4)
for name in ${names[@]}
do
        #do something
done
Run Code Online (Sandbox Code Playgroud)

但是,当我运行此脚本时,我收到以下错误:

./test.sh:line 6:意外令牌完成附近的语法错误'
./test.sh:line 6:done'

我错过了什么?shell脚本'tab敏感'?

syntax bash shell for-loop syntax-error

6
推荐指数
2
解决办法
3万
查看次数

从配置单元中的所有表中获取行数

如何使用配置单元从所有表中获取行计数.我对数据库名称,表名和行数感兴趣

hive hql

6
推荐指数
2
解决办法
5万
查看次数

在意外令牌"完成"附近出现Shell语法错误

该shell脚本应该将用户添加到系统中.新用户详细信息位于文件中.shell使用以下消息拒绝此脚本:

syntax error near unexpected token 'done'.
Run Code Online (Sandbox Code Playgroud)

怎么了?

#!/bin/bash
#Purpose: Automatically add new users in a linux system based upon the data found within a text file
#         Assign encryped passwords to each user
#         Add users to groups or create new groups for these users
#         Report errors and successful operations where necessary in log files
#         post help options (echo)

#Root validation
if [[ $(id -u) -eq 0 ]]; then
  #Argument validation
  if [[ -z "$1" ]]; then …
Run Code Online (Sandbox Code Playgroud)

shell token

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

标签 统计

shell ×5

bash ×3

error-handling ×1

for-loop ×1

hive ×1

hql ×1

linux ×1

loops ×1

sh ×1

syntax ×1

syntax-error ×1

token ×1

ubuntu ×1