sh

Issues using the tilde ~ in a simple function wrapper around scp

末鹿安然 提交于 2019-12-12 15:24:21
问题 I want place a simple bash function in my .bashrc that wraps around the scp command by accepting a 'source' argument and 'destination' argument, and so far have tried both function send() { eval "scp $1 user@annoyingly-long-server-name:$2" } and function send() { scp $1 user@annoyingly-long-server-name:$2 } ...but when I call either of the above a la send file.txt ~/ I get the error scp: home-directory-on-remote-machine: Operation not supported . After echoing each argument, it seems that the

How to run .profile inside a shell script in ubuntu

孤街醉人 提交于 2019-12-12 14:11:48
问题 I am running a script which is echoing the environment variables in .profile file and than I am running the script, but I am getting following error I tried following: node@node-virtual-machine:~$ cat env.sh #!/bin/bash echo 'export JAVA_HOME=/home/node/jdk1.6.0_45' >> /home/node/.profile echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /home/node/.profile cd /home/node/ source .profile node@node-virtual-machine:~$ sh env.sh sudo: source: command not found How to execute .profile within a script?

Execute permissions on downloaded file

五迷三道 提交于 2019-12-12 12:28:06
问题 I have made a script for installing a control panel. I've uploaded the script to a server so people can wget it to their machines. The only issue is that you have to chmod it after download. Is there a way to remove this step? How would I go about keeping 755 perms on the downloaded script? 回答1: When a user downloads the file, the file will automatically get some default permission. In UNIX, each user will have a default set of permissions which apply to all files created by that user, unless

How to iterate over the characters of a string in a POSIX shell script?

强颜欢笑 提交于 2019-12-12 12:23:19
问题 A POSIX compliant shell shall provide mechanisms like this to iterate over collections of strings: for x in $(seq 1 5); do echo $x done But, how do I iterate over each character of a word? 回答1: It's a little circuitous, but I think this'll work in any posix-compliant shell. I've tried it in dash , but I don't have busybox handy to test with. var='ab * cd' tmp="$var" # The loop will consume the variable, so make a temp copy first while [ -n "$tmp" ]; do rest="${tmp#?}" # All but the first

Fail if a script expects input or entering passwords

妖精的绣舞 提交于 2019-12-12 12:20:44
问题 I'm developing a script that should not need interaction with the user, and if a program inside my script needs the user to enter something, the script should fail and exit immediately. I have already closed the STDIN at the top of my script, and this works for some commands, but there are some that expect the input in another file descriptor (usually the ones asking for passwords like git or sudo ). Currently my script is: #!/bin/bash # close STDIN exec 0<&- # test that $1 exists and it is a

recursively “normalize” filenames

北城以北 提交于 2019-12-12 11:17:13
问题 This question was migrated from Super User because it can be answered on Stack Overflow. Migrated 8 years ago . i mean getting rid of special chars in filenames, etc. i have made a script, that can recursively rename files [http://pastebin.com/raw.php?i=kXeHbDQw]: e.g.: before: THIS i.s my file (1).txt after running the script: This-i-s-my-file-1.txt Ok. here it is: But: when i wanted to test it "fully", with filenames like this: ¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÂÃÄÅÆÇÈÊËÌÎÏÐÑÒÔÕ

use conditional in bash script to check string argument

大城市里の小女人 提交于 2019-12-12 07:41:27
问题 I am trying to write my shell script thing.sh so that upon making it an executable and running it with the single letter ``A" like so: $ ./thing.sh A I get the output A If argument 1 is not A, I want the output Not A Here is my code so far : #!/bin/bash if [ "$1" -eq "A"] then echo "A" else echo "Not A" fi which returns, no matter what I enter, ./thing.sh: line 3: [:missing `]' Not A I am trying what I hoped would check something with one or several letters and compare it against the letter A

increment variable in a string in shell script

怎甘沉沦 提交于 2019-12-12 06:57:51
问题 I have a string which comes from a variable I want to increment it. how can i do that using shell script? this is my input which comes from a variable: abc-ananya-01 output should be: abc-ananya-02 回答1: check this: kent$ echo "abc-ananya-07"|awk -F'-' -v OFS='-' '{$3=sprintf("%02d",++$3)}7' abc-ananya-08 The above codes do the increment and keep your number format. 回答2: It is shorter: a=abc-lhg-08 echo ${a%-*}-`printf "%02d" $((10#${a##*-}+1))` abc-lhg-09 Even better: a=abc-lhg-08 printf "%s-

jq not working with exclamation mark as an input [duplicate]

拟墨画扇 提交于 2019-12-12 06:22:02
问题 This question already has answers here : “Event not found” error for shell command in unix [duplicate] (1 answer) How do I escape an exclamation mark in bash? (3 answers) echo “#!” fails — “event not found” (5 answers) How to address error “bash: !d': event not found” in Bash command substitution [duplicate] (5 answers) Closed 2 years ago . I am passing username and password to jq the following way: json=$(jq -n --arg u "user_dev" --arg p "user!" '{username: $u, password: $p}') However, it is

expr: non-integer argument while doing Arithmetic in Shell Script [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-12 04:55:16
问题 This question already has answers here : Are shell scripts sensitive to encoding and line endings? (5 answers) Closed last year . When i'm trying to execute following line of code #!/bin/sh a=20 b=10 sum=`expr $a + $b` #(i thought i did wrong with ` so i put (') also to check but its becomes literals which gets printed as usual) echo $sum i'm getting the error expr: non-integer argument Can someone tell me where it went wrong in this code because almost on every tutorial same thing was