single="ls -l"

$single

=============

multi="ls -l | grep e"

echo $multi > tmp.sh
bash tmp.sh

=============

cmd="ls -l | grep e"
bash -c "$cmd"

=============

$ cmd="echo foo{bar,baz}"
$ $cmd
foo{bar,baz}
$ eval "$cmd"
foobar foobaz

=============

=============

eval "$1" executes the command in the current script. It can set and use shell variables from the current script, set environment variables for the current script, set and use functions from the current script, set the current directory, umask, limits and other attributes for the current script, and so on. bash "$1" executes the command in a completely separate script, which inherits environment variables, file descriptors and other process environment (but does not transmit any change back) but does not inherit internal shell settings (shell variables, functions, options, traps, etc.).

There is another way, (eval "$1"), which executes the command in a subshell: it inherits everything from the calling script but does not transmit any change back.

For example, assuming that the variable dir isn't exported and $1 is cd "$foo"; ls, then:

  • cd /starting/directory; foo=/somewhere/else; eval "$1"; pwd lists the content of /somewhere/else and prints /somewhere/else.
  • cd /starting/directory; foo=/somewhere/else; (eval "$1"); pwd lists the content of /somewhere/else and prints /starting/directory.
  • cd /starting/directory; foo=/somewhere/else; bash -c "$1"; pwd lists the content of /starting/directory (because cd "" doesn't change the current directory) and prints /starting/directory.

=============

# 注意:脚本文件必须是UNIX格式;脚本文件中没有空行,没有注释;

cat  /studies.sh  | while read line do   while [ 1 -eq 1 ]   do     declare -i fileLines     fileLines=`qstat -u hy | grep lq | sed -n '$=' `  echo -e "$fileLines \c"     if (($fileLines<50))     then    echo "$line"       eval "$line"    pwd       break     else       sleep 30     fi   done done

REF:

http://stackoverflow.com/questions/3469705/how-to-run-script-commands-from-variables

http://stackoverflow.com/questions/4668640/how-to-execute-command-stored-in-a-variable

http://unix.stackexchange.com/questions/124590/variable-as-command-eval-vs-bash-c

http://superuser.com/questions/679958/execute-a-command-stored-in-a-variable

http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html

http://www.tldp.org/LDP/abs/html/commandsub.html

http://ubuntuforums.org/showthread.php?t=1018434

Linux运行变量中的命名脚本的更多相关文章

  1. linux c程序中获取shell脚本输出的实现方法

    linux c程序中获取shell脚本输出的实现方法 1. 前言Unix界有一句名言:“一行shell脚本胜过万行C程序”,虽然这句话有些夸张,但不可否认的是,借助脚本确实能够极大的简化一些编程工作. ...

  2. linux C程序中获取shell脚本输出(如获取system命令输出)

    转载自 http://blog.csdn.net/hjxhjh/article/details/7909518 1. 前言 Unix 界有一句名言:“一行shell脚本胜过万行C程序”,虽然这句话有些 ...

  3. linux运行级别

    也许大家偶然会发现/sbin里有个init命令.你知道它是如何使用的吗? 如果你不喜欢使用图形登录方式,如何能够让用户在控制台下运行startx命令呢? 有时你要维护服务器,暂时不希望别的用户登录系统 ...

  4. Linux运行级详解

    对于那些在DOS/Win9x/NT平台下的高级用户而言,Linux似乎是一个怪物.没有config.sys,没有 autoexec.bat,具有个人特色的机器配置不知道从何开始. 需要说明的是,很多人 ...

  5. C++中嵌入Lua脚本环境搭建

    第一步(环境准备工作): 工具: ●LuaForWindows_v5.1.4-46.exe傻瓜式安装. 作用:此工具可以在windows环境下编译运行Lua脚本程序.安装完成后会有两个图标:Lua和S ...

  6. Linux中编写Bash脚本的10个技巧

    Shell 脚本编程 是你在 Linux 下学习或练习编程的最简单的方式.尤其对 系统管理员要处理着自动化任务,且要开发新的简单的实用程序或工具等(这里只是仅举几例)更是必备技能. 本文中,我们将分享 ...

  7. [转] linux下shell中使用上下键翻出历史命名时出现^[[A^[[A^[[A^[[B^[[B的问题解决,Linux使用退格键时出现^H解决方法

    [From] https://www.zmrbk.com/post-2030.html https://blog.csdn.net/suifengshiyu/article/details/40952 ...

  8. Linux环境变量设置中配置文件分析(/etc/profile,~/.bashrc等)(转)

    说明:在研究中发现,对于不同版本的Linux系统有着不同的文件,但是总的入口是不变的/etc/profile,下面只是展示加载顺序的研究过程,所以会有些系统没有这个文件等问题. 一.配置文件与作用域: ...

  9. linux系统 initrd.img中init启动脚本分析

    概述:这篇文章主体内容来源于网上转载.前面几篇文章倾向于制作initrd.img,这篇文章更倾向于initrd.img的运行过程:加载framebuff驱动 ide驱动和文件系统驱动,最后进入到真正的 ...

随机推荐

  1. 【pyQuery】抓取startup news首页

    #! /usr/bin/python # coding: utf-8 from pyquery import PyQuery c=PyQuery('http://news.dbanotes.net/' ...

  2. android 百度地图定位开发1

    首先注册成为百度开发者 然后进入百度开发者中心 点击LBS 跳到下一个页面 点击Android 开发 里面的基础地图 进入  点击获取密钥 进入   点击创建应用 进入     应用名称自己填 应用类 ...

  3. lamp环境编译错误

    GD 编译出错解决方法 编译最新的2.0.35版本,用默认的 ./configure编译 当make的时候,出现以下错误 configure.ac:64: error: possibly undefi ...

  4. python any()和all()用法

    #any(x)判断x对象是否为空对象,如果都为空.0.false,则返回false,如果不都为空.0.false,则返回true #all(x)如果all(x)参数x对象的所有元素不为0.''.Fal ...

  5. datatables中columns.render的使用

    可直接在columns申明中对应列下方使用render改变该列样式 也可单独在columnsDefs中用targets指定目标. "render":function(data,ty ...

  6. linux内核参数优化

    net.ipv4.ip_forward = 0net.ipv4.conf.default.rp_filter = 1net.ipv4.conf.default.accept_source_route ...

  7. oracle 日期问题

    共三部分: 第一部分:oracle sql日期比较: http://www.cnblogs.com/sopost/archive/2011/12/03/2275078.html 第二部分:Oracle ...

  8. JavaEE基础(二十三)/递归

    1.File类递归练习(统计该文件夹大小) 需求:1,从键盘接收一个文件夹路径,统计该文件夹大小 2.File类递归练习(删除该文件夹) 需求:2,从键盘接收一个文件夹路径,删除该文件夹 3.File ...

  9. iOS开发- 蓝牙后台接收数据(BLE4.0)

    最近在做一个蓝牙相关的项目, 需要在应用进入后台, 或者手机属于锁屏状态的情况下, 仍然保持蓝牙连接, 并且能正常接收数据. 本来以后会很麻烦, 但是学习了下..发现就2步而已.简单的不能再简单了. ...

  10. oracle数据库表空间文件收缩实例

    Oracle数据文件收缩实例 数据文件的作用 HWM的基本概念 查看数据文件的使用情况 包括内容:数据文件大小,已经used空间,free空间,hwm信息 select /*+ ordered use ...