bash

Can't access variables inside parenthesis in bash

不打扰是莪最后的温柔 提交于 2021-02-17 03:01:27
问题 In bash, if I run (foo=14) And then try to reference that variable later on in my bash script: echo "${foo}" I don't get anything. How can I make bash store this variable the way I need it to? Specifically, I am using this in an if statement and checking the exit code, something kind of like: if (bar="$(foo=14;echo "${foo}"|tr '1' 'a' 2>&1)") then echo "Setting "'$bar'" was a success. It is ${bar}" else echo "Setting "'$bar'" failed with a nonzero exit code." fi 回答1: Commands enclosed in

Passing Variables from a Shell-Script to a Fortran 90 Program

大兔子大兔子 提交于 2021-02-17 02:56:11
问题 I'm stuck on this little problem. I was wondering if it is possible to pass a variable of a bash-shell script to a f90 code? 回答1: I am pretty sure it was discussed here before, but I cannot find an exact duplicate. You can pass arguments directly as arguments to the program ./program arg1 arg2 you can retrieve the values in the program as character strings in Fortran 2003 using subroutines GET_COMMAND ARGUMENT and COMMAND_ARGUMENT_COUNT. Click on the links to get useful examples. In older

Quotes within HERE document in shell scripts

牧云@^-^@ 提交于 2021-02-17 02:53:31
问题 G'day, I'm getting syntax errors when working with a shell script like the following: ssh root@mm-$user-vm-lenny <<EOF check_dbtag=`grep "<<include /home/$user/cvs/dbtag.conf>>" /etc/dbtag.conf` if [ "$check_dbtag" == "" ] then echo '<<include /home/$user/cvs/dbtag.conf>>' >> /etc/dbtag.conf fi EOF The error I'm getting is -bash: line 21: syntax error near unexpected token 'newline' -bash: line 21: 'check_dbtag=<<include /home/thomasw/cvs/dbtag.conf>>' However, I don't get it anymore if I

Quotes within HERE document in shell scripts

只愿长相守 提交于 2021-02-17 02:52:11
问题 G'day, I'm getting syntax errors when working with a shell script like the following: ssh root@mm-$user-vm-lenny <<EOF check_dbtag=`grep "<<include /home/$user/cvs/dbtag.conf>>" /etc/dbtag.conf` if [ "$check_dbtag" == "" ] then echo '<<include /home/$user/cvs/dbtag.conf>>' >> /etc/dbtag.conf fi EOF The error I'm getting is -bash: line 21: syntax error near unexpected token 'newline' -bash: line 21: 'check_dbtag=<<include /home/thomasw/cvs/dbtag.conf>>' However, I don't get it anymore if I

How to install python packages from older version to newer version?

社会主义新天地 提交于 2021-02-17 02:06:46
问题 i was working with python 3.7 and i installed recently python 3.8 in linux. Is there any bash command or script that take a list of all packages of 3.7 and install it one by one in 3.8 version. i want to avoid to do it by hand every package. Note: i install them in my system not using venv. Thanks! 回答1: /path_to_3.7_bin/python -m pip freeze > /home/packages_list.txt then /path_to_3.8_bin/python -m pip install -r /home/packages_list.txt 回答2: try https://pip.pypa.io/en/stable/reference/pip

How to install python packages from older version to newer version?

落花浮王杯 提交于 2021-02-17 02:06:30
问题 i was working with python 3.7 and i installed recently python 3.8 in linux. Is there any bash command or script that take a list of all packages of 3.7 and install it one by one in 3.8 version. i want to avoid to do it by hand every package. Note: i install them in my system not using venv. Thanks! 回答1: /path_to_3.7_bin/python -m pip freeze > /home/packages_list.txt then /path_to_3.8_bin/python -m pip install -r /home/packages_list.txt 回答2: try https://pip.pypa.io/en/stable/reference/pip

docker概述与安装及运行容器

北城以北 提交于 2021-02-17 02:06:11
传统虚拟化 传统虚拟化步骤 1、安装虚拟化软件以及虚拟化的管理软件 2、创建虚拟机 3、给虚拟机安装os 4、在虚拟机内部不是应用(http、db之类的应用) 传统虚拟化的特点 1、VM与VM之间是完全隔离的,并且虚拟机必须要安装os 2、应用所运行的环境是建立在操作系统之上的 3、应用迁移非常笨重 传统虚拟化已经无法满足当前敏捷开发方式,VM的方式会导致开发环境和生产环境不一致,版本测试完成之后需要重新搭建环境。 docker docker是容器的引擎工具,最主要是管理容器的生命周期,创建容器、管理容器、管理镜像等。容器是没有操作系统的概念,容器通过image来启动。当你通过一个image创建和启动一个容器的时候,容器内的进程就已经启动了。一旦容器内的process意外退出,容器也就死亡。即进程在容器在,进程毁容器亡。容器与容器之间隔离通过namespace(命名空间隔离),对于Linux操作系统而言一定存在namespace,无需另外安装。 一个完整的docker由四个部分组成: docker client客户端 docker daemon守护进程 docker image镜像 docker container容器 docker功能特性 隔离环境(系统、网络、文件系统)与应用 解决依赖与版本问题 易于分发开箱即用 节点与容器快速扩容 镜像制作简单便捷,管理方便。 隔离

Deleting multiple words from a file using terminal

泪湿孤枕 提交于 2021-02-17 02:00:34
问题 I have a list of words word1 word2 word3 which I want to delete from a file file.txt . How can i do that using terminal. 回答1: Assuming that: Replacements should only occur for whole words, not just any substrings. Replacements should occur in-place - i.e., the results should be written back to the input file. GNU sed (adapted from @jaypal's comment): sed -r -i 's/\b(word1|word2|word3)\b//g' file.txt FreeBSD/OSX sed : sed -E -i '' 's/[[:<:]](word1|word2|word3)[[:>:]]//g' file.txt Variant

【MongoDB】用Docker安装一个MongoDB最新版玩玩

落花浮王杯 提交于 2021-02-17 01:02:18
1 安装 本文假设大家已经安装好了 docker 并能正常使用,所以不讲解如何安装 docker 了。用 docker 安装 MongoDB 最新版本如下: # 从repository查找mongo的相关镜像,结果很多,其中第一条为官方的镜像 $ docker search mongo # 下载官方镜像的最新版本 $ docker pull mongo:latest # 完成后,检查是否下载成功 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos 7 5e35e350aded 12 days ago 203MB mongo latest 965553e202a4 3 weeks ago 363MB hello-world latest fce289e99eb9 10 months ago 1.84kB 仅需要简单几个命令,我们就拥有了MongoDB的最新镜像了,后续就可以使用了。 2 启动 完成MongoDB的镜像下载后,启动就非常简单了,一个命令即可: $ docker run -itd --name mongo -p 27017:27017 mongo --auth 305ebd8236678905d16dd76e75dcf99fdd812be6b13c240acece7985d29b316c (1) -

Linux--shell练习题

我的梦境 提交于 2021-02-16 21:45:08
1、判断/etc/inittab文件是否大于100行,如果大于,则显示”/etc/inittab is a big file.”否者显示”/etc/inittab is a small file.” #!/bin/ bash #判断 /etc/inittab文件是否大于100行,如果大于,则显示“/etc/initabb is a big file . " 否则显示”/etc/inittab is a small file. " Line =` wc -l /etc/inittab | cut -d " " - f1` if [ $Line -gt 100 ]; then echo " /etc/initabb is a big file. " else echo " /etc/inittab is a small file. " fi 2、给定一个用户,来判断这个用户是什么用户,如果是管理员用户,则显示“该用户为管理员”,否则显示“该用户为普通用户” #!/bin/ bash #给定一个用户,来判断这个用户是什么用户,如果是管理员用户,则显示“该用户为管理员”,否则显示“该用户为普通 > 用户” a =` whoami ` str = " root " if [ $a = $str ]; then echo " 该用户为管理员 " else echo " 该用户为普通用户 "