我正在将一些软件从 Unix 迁移到 Linux。
我有以下脚本;它是文件传输的触发器。
命令的作用是什么exec?
它们也能在 Linux 上运行吗?
#!/bin/bash
flog=/mypath/log/mylog_$8.log
pid=$$
flog_otherlog=/mypath/log/started_script_${8}_${pid}.log
exec 6>&1
exec 7>&2
exec >> $flog
exec 2>&1
exec 1>&6
exec 2>&7
/usr/local/bin/sudo su - auser -c "/mypath/bin/started_script.sh $1 $pid $flog_otherlog $8"
Run Code Online (Sandbox Code Playgroud)
启动的脚本如下:
#!/bin/bash
flusso=$1
pidpadre=$2
flogcurr=$3
corrid=$4
pid=$$
exec >> $flogcurr
exec 2>&1
if [ $1 = pippo ] || [ $1 = pluto ] || [ $1 = paperino ]
then
fullfile=${myetlittin}/$flusso
filename="${flusso%.*}"
datafile=$(ls -le $fullfile | awk '{print $6, " ", $7, " ", $9, " ", $8 }')
dimfile=$(ls -le $fullfile | awk '{print $5 " " }')
aaaammgg=$(ls -E $fullfile | awk '{print $6}'| sed 's#-##g')
aaaamm=$(echo $aaaammgg | cut -c1-6)
dest_dir=${myetlwarehouse}/mypath/${aaaamm}
dest_name=${dest_dir}/${filename}_${aaaammgg}.CSV
mkdir -p $dest_dir
cp $fullfile $dest_name
rc_copia=$?
fi
Run Code Online (Sandbox Code Playgroud)
我将在Linux中更改为ls -le和ls -l --time-style="+%b %d %T %Y"更改。ls -Els -l --time-style=full-isoand
小智 11
exec [n]<&word将在 bash 中复制输入文件描述符。
exec [n]>&word将在 bash 中复制输出文件描述符。
请参阅 3.6.8: https: //www.gnu.org/software/bash/manual/html_node/Redirections.html
不过,参数的顺序可能会令人困惑。
在你的脚本中:
exec 6>&1创建文件描述符(即 STDOUT)的副本1,并将其存储为文件描述符6。
exec 1>&6复制6回1.
也可以通过附加破折号来移动它,即1<&6-关闭描述符6并仅保留1.
在两者之间,您通常会发现写入 STDOUT 和 STDIN 的操作,例如在子 shell 中。
另请参阅:移动文件描述符的实际用途
小智 6
exec {number x}>&{number y}将文件描述符 X 复制到 Y 中。
文件描述符的用法:
在您的情况下,它们应该早先在某个地方打开,例如exec 3<> /tmp/some_file将 fd3 设置为某个文件。
通常,您可以执行 exec2>&1将 stderr 输出重定向到 stdout。
您的 bash 示例并不完整,因为$8引用了给您的脚本的八个参数,因此我们在这里肯定缺少一些东西,例如参数 2-7...
| 归档时间: |
|
| 查看次数: |
3172 次 |
| 最近记录: |