对于想了解cygwintilde扩展无法在交互式shell中工作的读者,本文将是一篇不可错过的文章,我们将详细介绍无法嵌入互操作类型esri,并且为您提供关于BashShell;读命令;在Window
对于想了解cygwin tilde扩展无法在交互式shell中工作的读者,本文将是一篇不可错过的文章,我们将详细介绍无法嵌入互操作类型esri,并且为您提供关于Bash Shell;读命令;在Windows 7上使用Cygwin、bash – Powershell比cygwin / unix-shell更具优势、bash – 交互式shell技巧?、bash – 如何在交互式shell脚本中使“echo”ed行可编辑?的有价值信息。
本文目录一览:- cygwin tilde扩展无法在交互式shell中工作(无法嵌入互操作类型esri)
- Bash Shell;读命令;在Windows 7上使用Cygwin
- bash – Powershell比cygwin / unix-shell更具优势
- bash – 交互式shell技巧?
- bash – 如何在交互式shell脚本中使“echo”ed行可编辑?
cygwin tilde扩展无法在交互式shell中工作(无法嵌入互操作类型esri)
$ls ~ ls: cannot access : No such file or directory $ls ~/bin (lists /bin not $HOME/bin) $echo $HOME /home/myusername $echo ~ $
在最后一种情况下(echo~)没有输出(除了几个空行之外).
我在$HOME / .inputrc文件中设置了expand-tilde.还有其他我需要配置的东西吗?
解决方法
在任何情况下,解决方案都很简单:在你最喜欢的编辑器中打开/ etc / passwd,在你的用户名的行上,在第五和第六个冒号之间(最后一个和倒数第二个),写入正确的路径到你的主目录,即/ home / myusername.
/ etc / passwd中的相关行看起来如下所示:
meand:unused:12345:54321:PCNAME\meand,S-1-5-21-4567891230-654987321-312456978-58252:/home/meand:/bin/screen
Bash Shell;读命令;在Windows 7上使用Cygwin
所以我尝试了这个:
#!/bin/bash echo -e "Enter your name and press [ENTER]: \c" read var_name echo "Your name is: $var_name"
然后我将运行它并输入var_name的名称.
我明白了:
$./project1.sh Enter your name and press [ENTER]: Jake ': not a valid identifierad: `var_name Your name is:
据我所知,我遇到了阅读问题.我正在尝试为我的课程开展一个项目,但我似乎无法弄清楚为什么它不会读它.我毫不夸张地跟着这本书,然后在网上使用这些似乎对我不起作用的例子.有没有人知道这是我的设置还是我错过了什么,谢谢.
我建议这是因为该行:
': not a valid identifierad: `var_name
看起来像两条线一样可疑:
.........................ad: `var_name ': not a valid identifier
合并在一起(.字符表示已被覆盖的内容).
如果你在该行中的变量是var_namecarriage-return而不是更正常的var_name,那就是这种情况.
事实上它是Cygwin也指出了这个结论,因为当你使用Windows编辑器编辑你的脚本时经常遇到麻烦,这个编辑器使用CR / LF,其中Cygwin只需要LF.
我怀疑你会发现在你的实际脚本上做一个od -xcb表明你在一个或多个脚本行上有那些Windows行结尾.
事实上,我刚刚在Ubuntu下通过在读取行的末尾放置一个CTRL-M并输出(稍微修改以显示CTRL-M)来测试它:
pax@pax-desktop:~$od -xcb qq.sh ; ./qq.sh 0000000 2123 622f 6e69 622f 7361 0a68 6365 6f68 # ! / b i n / b a s h \n e c h o 043 041 057 142 151 156 057 142 141 163 150 012 145 143 150 157 0000020 2d20 2065 4522 746e 7265 7920 756f 2072 - e " E n t e r y o u r 040 055 145 040 042 105 156 164 145 162 040 171 157 165 162 040 0000040 616e 656d 6120 646e 7020 6572 7373 5b20 n a m e a n d p r e s s [ 156 141 155 145 040 141 156 144 040 160 162 145 163 163 040 133 0000060 4e45 4554 5d52 203a 635c 2022 720a 6165 E N T E R ] : \ c " \n r e a 105 116 124 105 122 135 072 040 134 143 042 040 012 162 145 141 0000100 2064 6176 5f72 616e 656d 0a0d 6365 6f68 d v a r _ n a m e \r \n e c h o ^^ 144 040 166 141 162 137 156 141 155 145 015 012 145 143 150 157 0000120 2220 6f59 7275 6e20 6d61 2065 7369 203a " Y o u r n a m e i s : 040 042 131 157 165 162 040 156 141 155 145 040 151 163 072 040 0000140 7624 7261 6e5f 6d61 2265 0a0a $ v a r _ n a m e " \n \n 044 166 141 162 137 156 141 155 145 042 012 012 0000154 Enter your name and press [ENTER]: pax ': not a valid identifierar_name Your name is:
换句话说,与您所看到的非常相似.
顺便说一句(现在我可以访问我的Cygwin环境),你看到的是输出:
abcdefghij.sh: line 99 read: `var_name `: not a valid identifier
第二行覆盖第一行,给出:
`: not a valid identifierad: `var_name
换句话说,奇怪的单词identifyierad实际上由标识符和最终广告组成:来自:之所以与上面的例子相似(而不是精确)是因为你的文件名和行号与我的小测试脚本不同.
bash – Powershell比cygwin / unix-shell更具优势
https://stackoverflow.com/questions/573623/#573861
bash – 交互式shell技巧?
我的,为bash:
将其添加到主目录中的.inputrc文件中:
"\e[A": history-search-backward "\e[B": history-search-forward
现在,当您在提示符处开始输入时,箭头键将在您的历史记录中搜索以您已键入的内容开头的任何其他命令.
bash – 如何在交互式shell脚本中使“echo”ed行可编辑?
这些是我尝试过的东西:
1)从编辑器获取输入,如下所示:
echo "$SUGGESTION\c" INPUT=`ed -` # problem with this approach is that 'ed' starts in command mode # by default,and I would need input mode
2)使用read -e
echo "$SUGGESTION\c" read -e INPUT # doesn't work as advertised
经过广泛的谷歌搜索,我确信2)应该工作,但事实并非如此.首先,我不能先删除$SUGGESTION而不先输入一些输入;键入一些字符后,退格键会删除整行,而不只是一个字符.
所以我的问题是:如何使“read -e”工作或是否有另一种方法来解决这个问题?非常感激您的帮忙!
解决方法
read -e -i "$SUGGESTION" INPUT
不幸的是,这只适用于Bash 4.
如果你有一个C编译器和readline可用,这里有一个你可以使用的快速入侵.将以下内容保存到myread.c(或其他)并编译它(您需要与readline链接).对于GCC,那将是:gcc -o myread myread.c -lreadline.
#include <stdio.h> #include <readline/readline.h> int main(int argc,char **argv) { if (argc != 2) return 1; // stuff the input buffer with the default value char *def = argv[1]; while (*def) { rl_stuff_char(*def); def++; } // let the user edit char *input = readline(0); if (!input) return 1; // write out the result to standard error fprintf(stderr,"%s",input); return 0; }
你可以像这样使用它:
myread "$SUGGESTION" 2> some_temp_file if [ $? -eq 0 ] ; then # some_temp_file contains the edited value fi
有很大的改进空间,但我想这是一个开始.
关于cygwin tilde扩展无法在交互式shell中工作和无法嵌入互操作类型esri的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于Bash Shell;读命令;在Windows 7上使用Cygwin、bash – Powershell比cygwin / unix-shell更具优势、bash – 交互式shell技巧?、bash – 如何在交互式shell脚本中使“echo”ed行可编辑?的相关信息,请在本站寻找。
本文标签: