尝试在从命令提示符处获取 args 作为数组项的同时对数组进行切片。问题是切片的位置参数不像我预期的那样工作。如何从提示中获取参数切片数组?
./arrays.bash awesome cool strong cute awesome
我想要
arr=$@
echo ${arr[*]:0:2} #awesome cool
Run Code Online (Sandbox Code Playgroud)
我得到
arr=$@
echo ${arr[*]:0:2} # aw
Run Code Online (Sandbox Code Playgroud)
我读了这篇文章:How to slice an array in bash 但我相信我的问题是不同的。似乎这里的困难在于,因为我是从命令提示符获取数组值,或者不是,idk。当数组作为变量包含在脚本中时,它确实按预期运行。这是来自learnyoubash,因此仅调整索引以删除字符而不是整个值,这确实返回正确答案,并不是解决问题的有效方法。我的解决方案不正确但有效的解决方案https://github.com/nodeschool/discussions/issues/2241
TL; DR
我不想export
每次登录时都使用变量。我想要它们在我的配置中。
来自文档
建议使用如上所述的环境变量。尽管可以在配置或代码中设置ENV和DEBUG,但强烈建议不要这样做。
我该怎么办?这怎么可能'?
更多-我尝试过的
我有一个flask.cfg
带FLASK_ENV='development'
。我跑步flask run
并且被development
打印。但是生产服务器已经启动。 它忽略以下内容:
app.config.from_pyfile("flask.cfg")
print(f"{app.config['ENV']}") => development
Run Code Online (Sandbox Code Playgroud)
这是一个无关紧要的个人项目。因此,为了方便起见,我忽略了最佳做法。
这绝对是重复的,但我尽可能多地浏览了其他答案,我首先在数字海洋论坛上发布,我联系了 DO 支持,但我仍然无法访问我的服务器。
我试过:
ssh-keygen
并制作一个名为 id_rsa3 的密钥(id_rsa 有效,但已被占用)。通过复制/粘贴将创建时的 SSH 密钥添加到 DO 仪表板。这个方法没有奏效。我摧毁了水滴并重新开始。ssh-copy-id -i ~/.ssh/id_rsa3 root@MY-IP
。然后就做了ssh -v -i ~/.ssh/id_rsa3 root@MY-IP
测试。Permission denied (publickey).
我摧毁了水滴并重新开始。/etc/ssh/authorized_keys
并粘贴与我的本地密钥匹配的公钥。然后ssh -v -i ~/.ssh/id_rsa3 root@MY-IP
进行测试。不过,Permission denied (publickey).
消灭水滴,再试一次。Created a ~/.ssh/config
and tried to get the droplet to choose the correct key. Might be some syntax problems here. It runs the config, but does not get the correct key.
Host sinatra_app
HostName 206.***.***.*04 …
我在父类向量中有多个子类,其中每个子类都有自己的类型。父级有一个虚getType
函数,每个子级都用它自己的覆盖它;甚至不确定我是否需要这个 TBH,但我从父类 C++ 中的这个Access 子成员那里得到了
当我循环遍历向量(此处未显示循环)时,类型只是父对象的类型,因为它是父对象的向量,但我需要使用它自己的构造函数创建的每个子对象的类型。
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Parent
{
private:
string type = "parent";
public:
virtual string getType()
{
return type;
}
};
class Child1 : public Parent
{
string type = "type1";
public:
string getType()
{
return type;
}
};
class Child2 : public Parent
{
string type = "type2";
public:
string getType()
{
return type;
}
};
//main.cpp
int main()
{
vector<Parent> children; …
Run Code Online (Sandbox Code Playgroud)