---
title: "关于shell读取文件"
author: "zhyt710"
date: "2010-05-14T10:40:31Z"
tags: []
categories: ["操作系统"]
slug: "shell"
draft: false
lastmod: "2010-05-14T10:40:31Z"
id: 666208
url: "https://zhyt710.iteye.com/blog/666208"
---

不想在shell上花费过多时间。只是想读取一个文件，并把文件中的内容设置给一个变量，成功代码如下

```
#!/bin/sh

thepath=''
#cat upper.sh | while read line
#do
#    echo $line
#    thepath=$thepath:$line
#done
#echo $thepath

while read line
do
  thepath=$thepath:$line
done < upper.sh
echo $thepath
```

 注意代码中注释掉的部分，由于管道的问题变量thepath不能设置成功。所以不得不用后面代码的部分方能成功设置变量。