(转) 一个从fedora7中拷贝过来的bash脚本,居然不能在ubuntu下面执行,提示错误 Bad for loop variable G了一把,在TW同胞那里找到了答案~原来是bash和dash的问题 解决方法: 使用 sudo dpkg-reconfigure dash 选择NO。。 世界又清静了~(经典!) 感谢link:http://hi.baidu.com/yk103/blog/item/1e9831fa3fc23d8c9e5146d0.html
错误如下: Syntax error: Bad for loop variable 分析: 从 ubuntu 6.10 开始,ubuntu 就将先前默认的bash shell 更换成了dash shell;其表现为 /bin/sh 链接倒了/bin/dash而不是传统的/bin/bash。 allen@allen-lql ~/workspace/script $ ls -l /bin/sh lrwxrwxrwx 1 root root 4 Aug 12 14:29 /bin/...
常用到的循环有for循环和while循环。下面就分别介绍一下两种循环的结构。【for循环】:Shell脚本中的for循环示例:#! /bin/bash ## author:Xiong Xuehao ## Use for in this script. for i in `seq 1 5`; do echo $i done脚本中的 shell脚本循环执行mysql 删除 for循环 bash while循环 转载 IT独行侠 ...
[root@www shell-script]# cat c_for02.sh#!/bin/bashfor((i=1,j=100;i<=10;i++,j--))doecho"i=$ij=$j"done 1. 2. 3. 4. 5. 6. for的无限循环 #!/bin/bashfor((i=0;i<1;i+=0))doecho"infinite loop"done 1. 2. 3. 4. 5. while循环 和for循环一样,while循环也是一种运...
1.bash -n 方式调试 bash -n script 这种方式读取shell脚本,但不实际执行, 用于测试Shell脚本中是否存在语法错误 2.使用-x参数调试:通过执行脚本时加 -x,可以使得脚本在执行时显示每一行命令及其参数。这种方法简单而实用,适用于小规模的调试任务。例子test2.sh脚本:#!/bin/bashname="John"age=30echo"...
Shell script 是解释型语言,而不是编译型语言shell 分好多种,如果想看你的操作系统中支持哪几种,可以执行如下命令: cat /etc/shells 输出如下(每个人的不一样): # List of acceptable shells for chpass(1). # Ftpd will not allow users to connect who are not using ...
Forexample,sayyourscriptneedstoreportaninvalidargumentthatisstoredinthe BADPARM variable. You can print the diagnostic message with the following line so that the script name appears in the error message:0变量保存脚本的名称,对于生成诊断消息非常有用。例如,假设您的脚本需要报告存储在 BADPARM变量中的...
实例for skill in Ada Coffe Action Java; do echo "I am good at ${skill}Script" done 如果不给skill变量加花括号,写成echo "I am good at $skillScript",解释器就会把$skillScript当成一个变量(其值为空),代码执行结果就不是我们期望的样子了。 推荐给所有变量加上花括号,这是个好的编程习惯。 已...
for skill in Ada Coffe Action Java do echo "I am good at ${skill}Script" Done 如果不给skill变量加花括号,写成echo "I am good at $skillScript",解释器就会把$skillScript当成一个变量(其值为空),代码执行结果就不是我们期望的样子了。(推荐使用花括号) 只读变量:使用 readonly 命令可以将变量定义...
fruit=orange; and on the third and final iteration,fruit=pear. Once it has completed the loop, the script continues normal execution with the next command after thedonestatement. In this case, it ends by saying “Let’s make a salad!” to show that it has ended the loop, but not the...