我不能在我的生活中看到为什么我无法读取while循环之外的postPrioity。 我试过“export postPrioity =”500“”仍然没有工作。无法读取while循环中存储的变量,当出现while循环时
任何想法?
- 或计划文本 -
#!/bin/bash
cat "/files.txt" | while read namesInFile; do
postPrioity="500"
#This one shows the "$postPrioity" varible, as '500'
echo "weeeeeeeeee ---> $postPrioity <--- 1"
done
#This one comes up with "" as the $postPrioity varible. GRRR
echo "weeeeeeeeee ---> $postPrioity <--- 2"
OUTPUT:(我只有在files.txt 3文件名)
weeeeeeeeee ---> 500 <--- 1
weeeeeeeeee ---> 500 <--- 1
weeeeeeeeee ---> 500 <--- 1
weeeeeeeeee ---> <--- 2
感谢证实我的猜测!我想在BashFAQ中提到的其他一些解决方法(例如命令分组)是更好的选择,但通常你的管道并不是毫无意义的。 – Cascabel 2009-10-07 06:12:02
当然,管道在每种情况下都不是毫无意义,但是构造“cat file | ...“应该在大多数情况下被替换为”... <文件“。见例如Bash指南:http://mywiki.wooledge.org/BashGuide#BashGuide.2BAC8-Practices.2BAC8-DontEverDoThese.Don.27t_Ever_Do_These – Philipp 2009-10-07 06:18:00
从来不知道这一点,你我知道一些关于subshell的。 但是,现在请记住这一点,并将在这些网站上阅读,谢谢。 – Mint 2009-10-07 06:24:10