gpt4 book ai didi

linux - 使用 Linux 在终端中运行脚本

转载 作者:太空宇宙 更新时间:2023-11-04 06:00:49 24 4
gpt4 key购买 nike

我尝试在终端中运行此脚本,但它不起作用并显示权限被拒绝。 scriptEmail 是文件名。

% find . -type d -exec ./scriptEmail {} \;

scriptEmail写法如下:

# !/bin/bash
# Mail Script
find gang-l -type f -name "*" -exec sh -c ' file = "$0" java RemoveHeaders "$file" > processed/$file ' {} ';'

我的读写权限

-rwxr-xr-x

最佳答案

关于权限:

  • 检查您的 shebang 是否位于文件的最顶部,并且它完全#! 开头; #! 不起作用
  • 检查您的文件是否被授予执行权限; chmod 750 scriptEmail 就可以了。
  • 检查您的文件是否使用 UNIX 换行符 - 对于 DOS 换行符,您的 shebang 可能有一个隐藏字符,使其指向实际上并不存在的解释器。
  • 检查您的文件存储的目录是否位于允许执行脚本的目录中(未使用 noexec 标志挂载,或位于不允许执行的 SELinux 上下文中)。

如果您的挂载点是 noexec 或者您创建可执行脚本的能力被 SELinux 或类似内容阻止,则使用 find 。 -type d -exec bash ./scriptEmail {}\; 显式指定解释器而不是尝试执行脚本。

<小时/>

第二:由于您已经使用 find 执行脚本 - 并使用它在目录中递归 - 您不需要在内部进行第二个 find (这可能会让您对 processed/dirA/dirB/file 以及 processed/dirB/fileprocessed/file 进行操作 - 对于目录不存在的所有这些都会出现错误)。

#!/bin/sh
cd "$1" || exit # if we can't cd to directory given in argument, exit.
mkdir -p processed || exit # if we can't create our output directory, exit.
for f in *; do # ...iterate through all directory contents...
[ -f "$f" ] || continue # ...if they aren't files, skip them...
java RemoveHeaders "$f" >processed/"$f" # run the processing for one item
done

关于linux - 使用 Linux 在终端中运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33741399/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com