zoukankan      html  css  js  c++  java
  • 简单Shell案例

    使用shell命令进行左对齐或者右对齐

    [root@bj-aws-yace-tbj mnt]# cat test.sh 
    #! /bin/bash
    
    
    file=./test.txt
    
    echo -e "
    左对齐
    "
    
    while read line
    do
            printf "%-30s %-10d %-10s
    " ${line}
    done < ${file}
    
    echo -e "
    右对齐
    "
    
    while read line
    do
            printf "%30s %10d %10s
    " ${line}
    done < ${file}
    [root@bj-aws-yace-tbj mnt]# cat test.txt 
        12,34,56a
       ada
      afd
    [root@bj-aws-yace-tbj mnt]# sh test.sh 
    
    左对齐
    
    12,34,56a                      0                    
    ada                            0                    
    afd                            0                    
    
    右对齐
    
                         12,34,56a          0           
                               ada          0           
                               afd          0           

    使用命令进行左对齐

    [root@bj-aws-yace-tbj mnt]# cat test.txt 
        12,34,56a
       ada
      afd
    [root@bj-aws-yace-tbj mnt]# column -t test.txt 
    12,34,56a
    ada
    afd
  • 相关阅读:
    多姿多彩的线程
    字典操作
    字符串语法
    购物车
    列表常用语法
    整数划分问题
    计算N的阶层
    判断是否是素数
    快速排序
    冒泡排序
  • 原文地址:https://www.cnblogs.com/xiewenming/p/9229938.html
Copyright © 2011-2022 走看看