如何使用一个变量来表示在bash文件描述符? [英] How to use a variable to indicate a file descriptor in bash?

查看:84
本文介绍了如何使用一个变量来表示在bash文件描述符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个bash变量来表示一个文件描述符,像这样的:

I want to use a bash variable to indicate a file descriptor, like this:

id=6
file=a
exec $id<>$file

但用法是错误的:

But the usage is wrong:

-bash: exec: 6: not found

那么,如何用一个变量来表示在exec命令文件描述符?

So, how to use a variable to indicate a file descriptor in exec command?

推荐答案

您必须使用评估,放在引号整个前pression。

You have to use eval and put the entire expression in quotes.

eval "exec $id<>$file"

和做,每次要使用的$ id

这篇关于如何使用一个变量来表示在bash文件描述符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆