linux 中 export命令

 

export命令扩大了变量的作用范围。

001、

root@DESKTOP-IDT9S0E:/home/test# ls
a.txt  record.sh
root@DESKTOP-IDT9S0E:/home/test# cat a.txt       ## 测试文件
01 02 03 04
05 06 07 08
09 10 11 12
root@DESKTOP-IDT9S0E:/home/test# cat record.sh    ## 测试命令
#!/bin/bash
cut -d " " -f $idx a.txt
root@DESKTOP-IDT9S0E:/home/test# idx=3            ## 变量
root@DESKTOP-IDT9S0E:/home/test# echo $idx
3
root@DESKTOP-IDT9S0E:/home/test# bash record.sh    ## shell中无法识别
cut: invalid field value ‘a.txt’
Try 'cut --help' for more information.
root@DESKTOP-IDT9S0E:/home/test# export idx=3      ## export处理
root@DESKTOP-IDT9S0E:/home/test# bash record.sh    ## shell中可以识别
03
07
11

 

 

posted @ 2023-05-12 09:00  小鲨鱼2018  阅读(48)  评论(0编辑  收藏  举报