linux system 执行shell脚本传参数的问题。。。
来源:互联网 发布:unity3d人物走动动画 编辑:程序博客网 时间:2024/04/26 23:35
问题:
我写的shell程序传入的参数是
s1 s2都是字符串。
s1是 -P 22 /home/
s2是/home
这样在程序中,直接system调用的话,会出现只把-P 22分别给了s1,s2,怎么处理这个问题,让-P 22 /home/
传给s1,/home传给s2?
解决方法:
使用system调用的话,必须使用字符串;
如下:
char str[1024];
char a1[] = "-P 22 /home/";
char a2[] = "/home";
sprintf(str, "a.sh \"%s\" \"%s\"", a1, a2);
system(str);
这样就可以了;
实验验证:
a1.sh#/bin/bash#ls |wc -lecho change_pppoe.sh '$1='$1--'$2'=$2a1.c#include <stdlib.h>#include <string.h>#include <stdio.h>#define MAX 1024#define PATH "~/a/home/a1.sh"int main(){ FILE *fp; char buffer[MAX]; sprintf(buffer, "~/a/home/a1.sh \"i am a girl!\" \"this is\""); printf("%s\n", buffer); system(buffer);}输出:[root@bogon home]# ./a1~/a/home/a1.sh "i am a girl!" "this is"change_pppoe.sh $1=i am a girl!--$2=this is验证完全正确
- linux system 执行shell脚本传参数的问题。。。
- Linux执行Shell脚本问题
- php无法执行system()的shell脚本但是Linux终端可以执行
- linux执行shell脚本的
- shell脚本的参数问题
- Linux下无法执行shell脚本问题
- system方法执行脚本遇到的问题
- linux执行shell脚本
- Linux执行shell脚本
- sudo在shell脚本执行的问题
- 一个shell脚本执行出错的问题
- Linux shell脚本的建立与执行
- Linux shell脚本的建立与执行
- Linux Shell之脚本的执行
- Linux shell脚本的建立与执行
- Linux shell脚本的建立与执行
- LINUX下用SHELL脚本执行带输入输出参数的ORACLE存储过程并得到结果
- shell 脚本的执行
- 虚函数 以及覆盖
- VS配置路径和宏
- jbpm涉及到的几个重要概念及常用API
- jQuery中添加自定义或函数方法
- Oracle -jdbc-java 的类型映射
- linux system 执行shell脚本传参数的问题。。。
- ubuntu下wine安装软件时乱码问题解决
- 测量运行时间
- 回文质数
- 利用Layer优化Group显示
- 一个简单的会签实例
- 李彦宏成长故事
- taskAffinity属性
- 升级论:电商为什么是一个可以赚钱的行业?