解析函数中的bash脚本参数是一种解决方法
run命令:./ script.sh -t -r -e
脚本:
#!/bin/sh
# parse argument function
parse_args() {
echo "$#" #<-- output: 0
}
# main
echo "$#" #<-- output: 3
# parsing arguments
parse_args
Run Code Online (Sandbox Code Playgroud) 我想传递一个函数作为参数.我知道你可以传递一个函数指针,就像我的例子中的第一个测试一样,但是可以像我的第二次测试一样传递一个hold函数(不是指针)吗?
#include <iostream>
using namespace std;
/* variable for function pointer */
void (*func)(int);
/* default output function */
void my_default(int x) {
cout << "x =" << "\t" << x << endl << endl;
}
/* entry */
int main() {
cout << "Test Programm\n\n";
/* 1. Test - default output function */
cout << "my_default\n";
func = &my_default; // WORK! OK!
func(5);
/* 2. Test - special output function 2 */
cout << "my_func2\n";
func = void my_func1(int …
Run Code Online (Sandbox Code Playgroud)