unix脚本 - 制作文本文件的问题 [英] unix script - problem in making a text file

查看:130
本文介绍了unix脚本 - 制作文本文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个简单的unix脚本如下:

I am writing a simple unix script as follows:

#!/bin/bash
mkdir tmp/temp1
cd tmp/temp1
echo "ab bc cj nn mm" > output.txt
grep 'ab' output.txt > newoutput.txt

我收到以下错误讯息:

grep : No such file or directory found output.txt

但是当我看着目录文本是创建output.txt ...但文件的类型是TXT ....我不知道什么是任何帮助??

but when I looked into the directory the text is created output.txt...but the type of the file was TXT....I am not sure what it is any help??

推荐答案

你可能有一个stray '\r' code> echo 命令。您正在创建一个名为output.txt\r的文件,然后尝试读取一个名为output.txt

You probably have a stray '\r' (carriage return) on the line with the echo command. You're creating a file called "output.txt\r", and then trying to read a file called "output.txt" without the carriage return.

修复脚本,使其使用Unix风格的行尾( \\\
而不是 \r\\\
)。您可以使用 unix2dos 命令。 (请注意, unix2dos 与大多数过滤器不同,会覆盖其输入文件。)

Fix the script so it uses Unix-style line endings (\n rather than \r\n). You can use the unix2dos command for this. (Note that unix2dos, unlike most filters, overwrites its input file.)

这篇关于unix脚本 - 制作文本文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆