- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
需要有关以下 korn shell 的帮助。语句 if (( ${lista[expr $FNO + 5]} == $MM ));
因语法错误而失败。获取 == 的语法错误。也试过 -eq 但同样的问题。
这不会返回任何内容:${lista[expr $FNO + 5]}
。如何在这里获取月份值?
#!/bin/ksh
# get a list of files and dates from ftp and remove files older than ndays
ftpsite="xxx.com"
ftpuser="ftpuser"
ftppass="ftppwd"
putdir="/ftpdir"
MM=`TZ=GMT+29 date +%b`
DD=`TZ=GMT+29 date +%d`
echo removing files older than $MM $DD
# get directory listing from remote source
listing=`ftp -i -n $ftpsite <<EOMYF
user $ftpuser $ftppass
binary
cd $putdir
ls -l
quit
EOMYF`
lista=$listing
# loop over our files
FNO=0
while (( $FNO < ${#lista[@]} )); do
# month (element 5), day (element 6) and filename (element 8)
#echo Date ${lista[`expr $FNO+5`]} ${lista[`expr $FNO+6`]} File: ${lista[`expr $FNO+8`]}
# check the date stamp
if (( "${lista[`expr $FNO + 5`]}" == $MM ));
then
if (("${lista[`expr $FNO + 6`]}" -lt $DD ));
then
# Remove this file
echo "Removing ${lista[`expr $FNO + 8`]}"
echo "Removing ${lista[`expr $FNO + 8`]}"
ftp -i -n $ftpsite <<EOMYF2
user $ftpuser $ftppass
binary
cd $putdir
delete ${lista[`expr $FNO+8`]}
quit
EOMYF2
fi
fi
(( FNO = $FNO + 9 ))
done
请为此寻求帮助。
谢谢你试图帮助我。是的,我从 pastebin 本身复制了它。当我尝试使用 ls *.txt 获得如下输出时,它没有获得 5 美元的值(value),因此,根据您的建议尝试 ls -l *.txt。我还能尝试什么?
下面是我从 pastebin 本身复制的脚本
#!/bin/ksh -px
# get a list of files and dates from ftp and remove files older than ndays
ftpsite="ftp.com"
ftpuser="ftpuser"
ftppass="ftppass"
putdir="/xxx/yyy"
MM=$(TZ=GMT+29 date +%b)
DD=$(TZ=GMT+29 date +%d)
echo "removing files older than $MM $DD"
# get directory listing from remote source
echo "
user $ftpuser $ftppass
binary
cd $putdir
ls *.txt
quit" | ftp -i -n $ftpsite | while read line; do
# line is *each line*, rather than a list of everything
# helps if the filenames have spaces. Just chomp into $0..
set -- $line
# month (element 5), day (element 6) and filename (element 8)
if (($# > 9)); then
echo "Can't deal with '$@'"
continue
fi
# check the date stamp
if [[ $5 == "$MM" ]];
then
if (($6 < $DD ));
then
# Remove this file
filename=$8
echo "Removing $filename"
# replace the ftp with cat with ftp $ftpsite
cat <<EOMYF2
ftp -n -i $ftpsite
user $ftpuser $ftppass
binary
cd $putdir
delete $filename
quit
EOMYF2
fi
fi
done
最佳答案
当您分配:lista=$listing
时,这是一个简单的变量分配。
您想将 listing
作为数组分配给 lista
。语法是:
set -A lista $listing
BTW, I'd use
$()
instead of backticks for command invocation, and use$((math))
instead ofexpr math
, as they're more ksh-fluent.
尝试调试文件的 ftp 列表:
ftpsite="xxx.com"
ftpuser="ftpuser"
ftppass="ftppwd"
putdir="/ftpdir"
ftp -i -n $ftpsite <<EOM
user $ftpuser $ftppass
binary
cd $putdir
ls -l *.txt
quit
EOM
这将列出所有考虑的文件 - 您需要确保它们都具有相同的格式。
一旦您确保格式符合预期的每行 9 个项目,您就可以尝试调试脚本。
关于linux - korn shell 脚本失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35619050/
我需要在使用 ksh 时将日期和主机名插入到行尾。这些行是从 vmstat os 输出的,如果一行以数字开头,我需要将 Date 和 Hostname 添加到行尾: 我有这个测试脚本: #!/usr/
需要帮助为以下内容编写 korn shell 脚本。 必须在目录..../script 中编写脚本 在目录 ..../files 中有以下文件 Have 2 file patterns xxx892_
需要有关以下 korn shell 的帮助。语句 if (( ${lista[expr $FNO + 5]} == $MM )); 因语法错误而失败。获取 == 的语法错误。也试过 -eq 但同样的问
应该在任何 shell 中运行的 env 和 start.env。它实际上确实如此,但 KORN 除外,其中 env 变量设置的行为与我期望的不同。所以看例子。 文件 set.env : #!/bin
我对 Korn shell 语法感到困惑。我需要读取当前目录的所有文件并将它们分配给一个数组。然而。我需要排除目录。下面的代码也包含我不想要的目录。另外,我无法获得要分配给我的阵列的文件名。 file
以下: #!/bin/sh FOX="{ab,cd}" echo $FOX 输出我所期望的 ({ab,cd}) 但是: #!/bin/ksh FOX="{ab,cd}" echo $FOX 把逗号变成
我必须使用 ksh88 提取子字符串。 (顺便说一句,查找 ksh $KSH_VERSION 版本的简单方法对我不起作用。我不得不使用 [ "`echo "\c" | grep c`" ] && e
我是使用Java的新手,我想从unix执行Java程序,而在尝试执行它时,出现以下错误: Exception in thread "main" java.lang.UnsupportedClassVe
在给定变量名称后,ksh 中是否有一种方法可以获取变量的值? 例如: #!/usr/bin/ksh var_name=$1 #pretend here that the user passed th
我坚持尝试创建一个别名,该别名将 cd 返回一个目录,创建一个具有给定名称的新目录,然后 cd 进入该目录。这是我目前所拥有的: 别名 cdmk="cd .. | mkdir '$1' | cd '$
我对 docker 很陌生,我想将 Linux Korn Shell 添加到现有容器中。 我使用了这个命令: yum install ksh 我收到这些错误: fastesmirror
我正在使用 while 循环逐行读取文件,例如,如果文件包含如下行: ABC.///.AB_SWift_ABC 我需要将其替换为 ABC.slashslashslash.AB_SWift_ABC 如何
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我在尝试为循环中的变量赋值时遇到问题。这就像在变量中使用变量一样。所以我创建了一个数组来添加值仍然是不正确的。 请看一下下面的 KornShell (ksh) 脚本,让我知道我哪里搞砸了 #!/usr
这是我在 shell 脚本中的命令。 x=($(echo $x1 | cut -f3 -d" " | cut -f1 -d"]")) syntax error at line 818 : `(' un
我们需要支持提供 Unix 和 Win32 端口的旧版应用程序。不幸的是,在游戏后期,大量的胶水代码是用ksh脚本编写的,只针对unix端口,Win32端口失去了奇偶校验。我一直在尝试恢复它,并且我一
我想在 shell 脚本中执行此操作: #!/usr/bin/ksh PERL_PATH=/usr/local/bin/perl RET1=$(${PERL_PATH} missing_months_
我正在尝试重定向 UNIX 命令的 STDOUT/STDERR 并附加到 korn shell 中的日志文件。 rm -rf file1 >>& 日志文件 这个命令可以在 ksh 中工作还是一个典型的
我得到“美国/芝加哥”时区的日期和时间。 我的本地时区是“澳大利亚/墨尔本”。 我需要将“美国/芝加哥”时区的日期/时间转换为本地时区(“澳大利亚/墨尔本”) 我知道如何将本地时区的日期/时间转换
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 9 年前。 Improve
我是一名优秀的程序员,十分优秀!