shell script - usuage of the for loop

for varname in list
do
 command1
 command2
 ..
done
  • for, in, do and done are keywords
  • “list” contains list of values. The list can be a variable that contains several words separated by spaces. If list is missing in the for statement, then it takes the positional parameter that were passed into the shell.
  • varname is any Bash variable name.
 cat for1.sh
i=1
for day in Mon Tue Wed Thu Fri
do
 echo "Weekday $((i++)) : $day"
done

$ ./for1.sh
Weekday 1 : Mon
Weekday 2 : Tue
Weekday 3 : Wed
Weekday 4 : Thu
Weekday 5 : Fri


 How will you go about concatenating the contents in a number of text/sql files to a single file?The account_sqls.patch file contains the following entries to a number of SQL files to be executed sequentially.


 
 
?
1
2
3
4
./tables/account_summary.sql
./tables/account_detail.sql
./tables/account_history.sql
./tables/account_link.sql
How will you combine the SQL contents in the above 4 files into one?  A. Firstly, cd to the folder where the account_sqls.patch file is, and then type the following command on a shell command line.
?
1
for sql in $(sed -n '1,4p' account_sqls.patch); do cat $sql >> accounts_combined.sql; d

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值