微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

读取指定的文件行,并从已经使用该文件的单词创build新的目录

for file in $* head -n 1 $file | while read folder do mkdir $directory $folder done

大家好,我的脚本有问题。 我想要做的是:从我指定的文件中读取第一行,并从我从该文件中取出的单词在指定的目录中创build新的目录。

我得到这样的错误

./scriptas: line 2: Syntax error near unexpected token `head' ./scriptas: line 2: `head -n 1 $file | while read folder'

而我的第二个问题是:如何从命令行(putty)$目录添加第二个variables?

例如我有文本文件

参数列表太长 – Unix

一个windowsbatch filevariables设置为星期几

在linux bash脚本中恢复

在shell中水平显示两个文件

在grep中的每个结果之后添加空行

one two three five seven nine eleven okey

我需要脚本采取第一行,并创build目录“一”“两”“三”

Windows Management Instrumentation命令行WMIC批量提取属性

Windowsbatch file文件从URL下载

无法在Cygwin中作为KornShell脚本执行shell脚本

如何使用MsgBox在VBS中正确configuration用户input的条件操作?

用awk实现尾部

你必须在for / while循环之前把命令放在前面。

你的代码看起来应该像这样:

#!/bin/bash files=$* for file in $files do head -n1 "$file" | while read dname do mkdir $dname done done

至于其他变量,简单的语法是$符号后面的数字。

所以你可以做

files="$1" directory="$2"

然后运行脚本

./script.sh "file1.txt file2.txt file3.txt" dir2

更复杂的解决方包括getopts等….

更新了脚本。 你可以这样使用它:script.sh“one.txt two.txt three.txt”destdir

#! /bin/bash for files in $1 do for i in $(head -n 1 $files) do if [ -z $2 ] then mkdir $i else mkdir $2/$i -p fi done done

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐