Shell 中字符串变量的赋值注意点
1. 变量赋值
语法:var="saaaa"
PS: 等号两边不能有空格
2. 脚本示例如下:
#!/bin/sh
# Get bug activity info
# usage get_bug_activity <bug_id_list_file>
if [ $# -lt 2 ]; then
echo "Usage:";
echo "$0 <blk_pair_id_list_file> <dir>";
exit;
fi
if [ ! -d $2 ]; then
echo "make DIR $2";
mkdir $2;
fi
echo -e "processing bug list file \033[1;31m$1\033[m";
n=0
m=0
cat $1 | while read line # read file $1 line by line
do
BugID=`echo ${line%%[A-Z]*} | sed 's/[ \t]*$//g'`; # get Bugid from each line $line,
# and remove the space of the string tail
# PS: BugID="***" right; BugID = "***" wrong
# There should no space between "=
let n=n+1;
echo -e "\033[1;35m$n\033[m $BugID";
rfile="$2/a$BugID.htm";
if [ ! -f "$rfile" ]; then
curl "https://bugs.eclipse.org/bugs/show_activity.cgi?id=$BugID" -o "$rfile";
else
let m=m+1;
echo -e "\033[1;31mfile existed...\033[m $m duplicated";
fi
done
echo "finished";
3. 示例讲解
echo -e "processing bug list file \033[1;31m$1\033[m";: 用来设置变量$1 的颜色。\033[1;31m红色文字\033[m.- 逐行读取文件内容到
$line
cat $1 | while read line # read file $1 line by line
do
## do something
done
- 将读到的内容只截取第一个字段 (后面可能会有一些空格):
echo ${line%%[A-Z]*}. - 用sed 删除字符串最后的空格 :
echo ${line%%[A-Z]*} | sed 's/[ \t]*$//g - 访问网址,并输出到文件
$rfile。
curl "https://bugs.eclipse.org/bugs/show_activity.cgi?id=$BugID" -o "$rfile"
Shell 中字符串变量的赋值注意点的更多相关文章
- shell中的变量a=100, 什么时候作整数使用, 什么时候作字符串使用呢?
shell中的变量a=100, 什么时候作整数使用, 什么时候作字符串使用呢? 这确实是一个困扰很久的一个问题? how it can be an issue? 事实上, 在shell中, 你可以认为 ...
- shell专题(四):Shell中的变量
4.1 系统变量 1. 常用系统变量 $HOME.$PWD.$SHELL.$USER等 2.案例实操 (1)查看系统变量的值 [atguigu@hadoop101 datas]$ echo $HOME ...
- SHELL 中的变量
变量的分类 系统环境变量 系统本身所有,通常为大写字母 系统变量通过 set 或 declare 指令进行查看 UDV 变量(user defined variable ) 用户创建和维护,建议大写 ...
- C Shell中的变量数组
今天刚刚在看一点C Shell的内容,发现一个挺好玩的东西!就是环境变量可以像数组那样来设置!具体设置语法如下: set variable=(element1 element2 ...) //注意元素 ...
- shell中字符串操作【转】
转自:http://blog.chinaunix.net/uid-29091195-id-3974751.html 我们所遇到的编程语言中(汇编除外)都少不了字符串处理函数吧,当然shell编程也不例 ...
- Shell中字符串、数值的比较
原文:http://apps.hi.baidu.com/share/detail/31263915 在shell中字符串与数值的比较方法是不同的,要注意区分 整数比较: -eq 等于 ...
- Linux Shell中的变量声明和一些特殊变量
在SHELL中定义变量比较直接,无类型区别,不需要像Java那样定义好是String还是int等. 声明变量需要遵守或者注意的几点: 变量名和等号之间不能有空格. 变量名首字符必须为字母. 变量名里可 ...
- (二)shell中的变量
1.常用系统变量 $HOME.$PWD.$SHELL.$USER等 2.自定义变量 基本语法: (1)定量变量:变量=值 (2)撤销变量:unset 变量 (3)声明静态变量:readonly变量 注 ...
- Shell总结02-shell变量、赋值与替换
变量 shell并不区分变量的类型,或者说变量都是弱类型的,本质上都是字符串,但是如果变量值中只含有数字,shell还是支持对其进行算术运算 赋值 常见的赋值操作符有=(在其前后没有空白符)和let ...
随机推荐
- 通过yum安装php7
Linux下全局安装composer方法: //下载composercurl -sS https://getcomposer.org/installer | php //将composer.phar文 ...
- JSON数据的解析和生成(C++)
安装 "JSON for Modern C++" $ brew tap nlohmann/json $ brew install nlohmann_json 安装之后将/usr/l ...
- 最适合入门的Laravel中级教程(四)前端开发
Laravel 使用 npm 安装前端依赖: npm 是一个类似 composer 的工具: 用于管理前端的各种依赖包: 在使用之前需要先安装 node : Windows 下可以在官网下载安装: h ...
- int和string之间的转换
#include<cstring> #include<algorithm> #include<stdio.h> #include<iostream> # ...
- ajax----tomact服务器运行
一.菜鸟教程的代码本地运行 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- spring cloud 总结
Finchley版本Spring Cloud Finchley; Spring Boot 2.0.3 史上最简单的 SpringCloud 教程 | 第一篇: 服务的注册与发现(Eureka)(Fin ...
- EnterpriseLibrary
收藏一下: http://www.cnblogs.com/huangcong/archive/2010/06/01/1748672.html
- 41 【docker】初识
常用的docker命令: docker ps #查看当前正在运行的容器 docker ps -a | grep <keyword> #查看所有的容器,运行的或者停止的 docker sto ...
- [leetcode]10. Regular Expression Matching正则表达式的匹配
Given an input string (s) and a pattern (p), implement regular expression matching with support for ...
- [leetcode]19. Remove Nth Node From End of List删除链表倒数第N个节点
Given a linked list, remove the n-th node from the end of list and return its head. Example: Given l ...