我想实现一个bash进入 running的自动脚本docker container,并做一些事情:
# cat docker.sh
#!/bin/bash -x
docker exec -it hammerdb_net8 bash
cd /data/oracle/tablespaces/
pwd
Run Code Online (Sandbox Code Playgroud)
在终端上执行脚本:
# ./docker.sh
+ docker exec -it hammerdb_net8 bash
[root@npar1 /]#
Run Code Online (Sandbox Code Playgroud)
输出只显示登录docker container,不做其他操作。
有什么方法可以自动输入docker container和做其他事情吗?
我阅读了本教程并尝试了以下Rust代码:
fn main() {
let x = ~10;
println!("{:d}", *x);
}
Run Code Online (Sandbox Code Playgroud)
但编译器抱怨:
rustc 1.16.0 (30cf806ef 2017-03-10)
error: expected expression, found `~`
--> <anon>:2:13
|
2 | let x = ~10;
| ^
error: unknown format trait `d`
--> <anon>:3:22
|
3 | println!("{:d}", *x);
| ^^
Run Code Online (Sandbox Code Playgroud)
是let x = ~10;过时了吗?
检查以下C++代码:
#include <string>
#include <map>
class A
{
public:
A (int a) {};
};
int main()
{
std::map<std::string, A> p;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译成功.虽然变化std::map到std::pair:
#include <string>
#include <utility>
class A
{
public:
A (int a) {};
};
int main()
{
std::pair<std::string, A> p;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译器会抱怨:
$ clang++ test.cpp
In file included from test.cpp:1:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/string:40:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/char_traits.h:39:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/stl_algobase.h:64:
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/stl_pair.h:219:18: error: no matching …Run Code Online (Sandbox Code Playgroud) 当我编写C程序时,经常需要命名一个这样的函数:conn_pool_init(在这个函数中,初始化连接池,并启动它)。
我经常考虑什么是最好的相反函数名称。我见过诸如 conn_pool_end、conn_pool_stop 或 conn_pool_deinit 之类的。所以我想问是否有一个与“xxx_init”相反的约定名称?
我在Solaris 10上构建redis C客户端,生成动态库的最后一步是这样的:
cc -G -o libhiredis.so -h libhiredis.so.0.11 net.o hiredis.o sds.o async.o
Run Code Online (Sandbox Code Playgroud)
该cc指gcc:
bash-3.00# which cc
/usr/local/bin/cc
bash-3.00# ls -lt /usr/local/bin/cc
lrwxrwxrwx 1 root root 3 Mar 24 2011 /usr/local/bin/cc -> gcc
bash-3.00# /usr/local/bin/gcc -v
Reading specs from /data/local/bin/../lib/gcc/sparc-sun-solaris2.10/3.4.6/specs
Configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld -- enable-shared --enable-languages=c,c++,f77
Thread model: posix
gcc version 3.4.6
Run Code Online (Sandbox Code Playgroud)
从https://gcc.gnu.org/onlinedocs/gcc/Option-Index.html,我知道"-G"选项是"创建共享对象".但是"-h"是什么意思?我在https://gcc.gnu.org/onlinedocs/gcc/Option-Index.html中找不到它.
我使用Spark的Windows。我知道,在*nix访问本地文件代码是这样的:
val textFile = sc.textFile("file:///usr/local/spark/README.md")
Run Code Online (Sandbox Code Playgroud)
但是如何访问本地文件Windows?我尝试了以下方法:
val logFile = "C:\spark-1.3.1-bin-hadoop2.4\README.md"
val logFile = "file\\C:\spark-1.3.1-bin-hadoop2.4\README.md"
Run Code Online (Sandbox Code Playgroud)
但是,一切都行不通。
是type variable和type parameter哈斯克尔是一回事吗?例如:
ghci> :t last
last :: [a] -> a
Run Code Online (Sandbox Code Playgroud)
a是type variable和type parameter.
检查这个C程序:
#include <stdio.h>
int main(void) {
// your code goes here
char **p = NULL;
printf("%d,%d\n", sizeof(*p), sizeof(**p));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
执行上面的代码,结果是:
8,1
Run Code Online (Sandbox Code Playgroud)
虽然p是NULL,它不会导致程序崩溃sizeof(*p)和sizeof(**p).如何理解这种行为?它是否符合c规范?
检查以下简单C程序:
#include <stdio.h>
int main(void)
{
char str[4] = {1, 1, 1, 1};
snprintf(str, sizeof(str), "%s%s", "a", NULL);
printf("%s\n", str);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
构建并运行它Linux:
$ gcc test.c
$ ./a.out
a(n
Run Code Online (Sandbox Code Playgroud)
如何理解输出中(n出现的" "字符a?我希望当snprintf遇到NULL争论时,它会停止处理.顺便说一下,我无法从snprintf 手册中找到相关信息.