bash

How to source an external file in .bash_profile in OSX?

妖精的绣舞 提交于 2021-02-10 13:19:07
问题 I have defined some aliases in my .bash_profile file and aliases work as expected. e.g alias python-server="python -m SimpleHTTPServer 7070" And, When I open new terminal, typing python-server opens up a python server with current directory as root (or "/"). But I have around 10 aliases and I want to backup the aliases So I thought to create an external file which contain these aliases and am trying to source that file from .bash_profile like this source ~/personal/Dropbox/scripts/aliases.sh

Why does this shell script work for one instance and not the other? [duplicate]

徘徊边缘 提交于 2021-02-10 13:17:14
问题 This question already has answers here : How to cat <<EOF >> a file containing code? (4 answers) Closed 2 years ago . I'm in need of some explanation of the following code, because they are the same concepts but not working the same. So, I'm trying to do the following: #!/bin/sh ssh -T username@host << EOF relative="$HOME/Documents" command=$(find \$relative -name GitHub) command2=$(echo \$relative) echo "HERE: \$command" echo "HERE: \$command2" EOF Here is the output I get: find: ‘$relative’

What does sleep 0 do in a shell script and what does it do if it used in the ansible SSH config to append after each command?

笑着哭i 提交于 2021-02-10 12:47:53
问题 What does sleep 0 do in a shell script? I read the man page for sleep and it says "delay for a specified amount of time" And the argument NUMBER specifies this time in SECONDS (by default). But I see ansible using sh -c 'echo ~ec2-user && sleep 0' to start with each task. Also, it uses this at the end of each remote command it is firing. I didn't find any special case mention of sleep 0 on the man page and based on the functionality of the sleep command it doesn't make any sense to have sleep

how to echo text containing with double quotes [duplicate]

孤街浪徒 提交于 2021-02-10 12:47:29
问题 This question already has answers here : How can I escape a double quote inside double quotes? (8 answers) Difference between single and double quotes in Bash (6 answers) Closed 2 months ago . I need to echo some text. like text "hey" If i try with code echo "text "hey"" getting output as text hey So, how to display the double quotes also. Can anyone help me with this. 回答1: You can use echo 'text "hey"' or echo "text \"hey\"" In short: The double quote ( "quote" ) protects everything enclosed

How can I check if a variable is contains only letters

☆樱花仙子☆ 提交于 2021-02-10 12:29:28
问题 I tried to check the following case: #!/bin/bash line="abc" if [[ "${line}" != [a-z] ]]; then echo INVALID fi And I get INVALID as output. But why? It's no check if $line contains only a characters in the range [a-z] ? 回答1: Use the regular expression matching operator =~ : #!/bin/bash line="abc" if [[ "${line}" =~ [^a-zA-Z] ]]; then echo INVALID fi 回答2: Works in any Bourne shell and wastes no pipes/forks: case $var in ("") echo "empty";; (*[!a-z]*) echo "contains a non-alphabetic";; (*) echo

Bash regex with hyphen and dot

岁酱吖の 提交于 2021-02-10 12:23:06
问题 I'm trying to match hostname with regex. For some reason the following code fails. #!/bin/bash CONFIGURATION=m1si-ngxi-ddb01 #check configuration format TMP_CONFIGURATION=",${CONFIGURATION}" re=',[a-zA-Z0-9\-_\.]+' if ! [[ $TMP_CONFIGURATION =~ $re ]] then echo "configuration parttern mismatch." exit 1 fi Testing: [oracle@m1s-nyyy-db01 nir]$ vi a.sh [oracle@m1s-nyyy-db01 nir]$ 回答1: The pattern you have is failing due to "escaped" chars and the fact that - is not at the end/start of the

Pipe One Serial Port to Another in Linux [closed]

本小妞迷上赌 提交于 2021-02-10 09:30:10
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Improve this question I am looking for a means to pipe one serial ports data (regardless of data type) to another serial port. In my case I am trying to take in data from one serial port and output it through a radio connected to another serial port in real time. I already know what

Http post 常用的四种请求方式

纵饮孤独 提交于 2021-02-10 08:59:08
http1.1协议 规定http 的请求方式有OPTIONS、GET、HEAD、POST、PUT、DELETE、TRACE、CONNECT几种方式。其中POST是一种最常用的向服务器提交数据的方法,本文主要讨论POST提交数据的四种方式。 application/x-www-form-urlencoded 这应该是最常见的 POST 提交数据的方式了。浏览器的原生 <form> 表单,如果不设置 enctype 属性,那么最终就会以 application/x-www-form-urlencoded 方式提交数据。请求类似于下面这样(无关的请求头在本文中都省略掉了): POST http://www.example.com HTTP/1.1 Content-Type: application/x-www-form-urlencoded;charset=utf-8 title=test&sub%5B%5D=1&sub%5B%5D=2&sub%5B%5D=3 首先,Content-Type 被指定为 application/x-www-form-urlencoded;其次,提交的数据按照 key1=val1&key2=val2 的方式进行编码,key 和 val 都进行了 URL 转码。大部分服务端语言都对这种方式有很好的支持。例如 PHP 中,$_POST['title']

Bash split file on double newline

痞子三分冷 提交于 2021-02-10 07:14:41
问题 I have some files with content that change from file to file. Each file have 2 sections of lines separated by a blank line. I never know how many lines or characters there are in either section. The file can look something like this. This is a file with some text and some more text This code only gives the first line from each section. awk 'BEGIN {RS="\n\n"; FS="\n";} {print $1 }' file I need each section split up to work with. 回答1: Prints first part: sed '/^$/q' test.txt Prints second part:

Bash split file on double newline

北城余情 提交于 2021-02-10 07:13:31
问题 I have some files with content that change from file to file. Each file have 2 sections of lines separated by a blank line. I never know how many lines or characters there are in either section. The file can look something like this. This is a file with some text and some more text This code only gives the first line from each section. awk 'BEGIN {RS="\n\n"; FS="\n";} {print $1 }' file I need each section split up to work with. 回答1: Prints first part: sed '/^$/q' test.txt Prints second part: