sh

Is it necessary to specify traps other than EXIT?

牧云@^-^@ 提交于 2019-12-03 06:36:17
问题 I see a lot of shell scripts that do: trap cmd 0 1 2 3 13 15 # EXIT HUP INT QUIT PIPE TERM In every shell I have access to at the moment, all the traps other than 0 are redundant, and cmd will be executed upon receipt of a signal if the trap is simply specified: trap cmd 0 Is the latter specification sufficient, or do some shells require the other signals to be specified? 回答1: I think trap 0 is executed just prior to script termination in all cases, so is useful for cleanup functionality

Remove line breaks in Bourne Shell from variable

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 06:01:11
In bourne shell I have the following: VALUES=`some command that returns multiple line values` echo $VALUES Looks like: "ONE" "TWO" "THREE" "FOUR" I would like it to look like: "ONE" "TWO" "THREE" "FOUR" Can anyone help? echo $VALUES | tr '\n' ' ' Another method, if you want to not just print out your code but assign it to a variable, and not have a spurious space at the end: $ var=$(tail -1 /etc/passwd; tail -1 /etc/passwd) $ echo "$var" apache:x:48:48:Apache:/var/www:/sbin/nologin apache:x:48:48:Apache:/var/www:/sbin/nologin $ var=$(echo $var) $ echo "$var" apache:x:48:48:Apache:/var/www:

How do I overwrite multiple lines in a shell script?

假如想象 提交于 2019-12-03 05:06:43
I want to write multiple lines over and over to the terminal. Something like echo "One Line" echo "Two Lines" echo "\r\b\rThree Lines" echo "Four Lines" Ideally this would first output: One Line Two Lines And this output would then be replaced with Three Lines Four Lines Trouble is, while the carriage return will let you overwrite one line of output, you can't get past the \n with a \b. How do I then overwrite multiple lines? I found a solution for this one that took a little digging and I'm still not entirely sure on how this one works. However, it seems the program tput will allow you to get

Rename files recursively Mac OSX

ⅰ亾dé卋堺 提交于 2019-12-03 03:13:54
问题 Attempting to rename a bunch of files. I can rename any instances of foo with bar in the current directory with: ls . | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2' | /bin/sh What can I add to make it recursive? Edit/My solution I don't know/understand this shell type stuff so I did it with some (pretty dirty) Ruby: 5.times do Dir["**/*"].each do |f| file_name = File.absolute_path f should_rename = file_name.include? "yolo" new_file_name = file_name.gsub("yolo", "#{@project_name}") File

What is sudo bang bang? [closed]

核能气质少年 提交于 2019-12-03 01:28:32
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Besides from this comic, I have seen some people write sudo !! . What is sudo bang bang? 回答1: The bang bang ( !! ) command is a shortcut to repeat the previous command you entered in your terminal . This command is very useful when you forget that you need admin rights to make a certain action, and lets you

How can I tell if a file is older than 30 minutes from /bin/sh?

爱⌒轻易说出口 提交于 2019-12-03 00:59:04
How do I write a script to determine if a file is older than 30 minutes in /bin/sh? Unfortunately does not the stat command exist in the system. It is an old Unix system, http://en.wikipedia.org/wiki/Interactive_Unix Perl is unfortunately not installed on the system and the customer does not want to install it, and nothing else either. Schwern Here's one way using find . if test "`find file -mmin +30`" The find command must be quoted in case the file in question contains spaces or special characters. The following gives you the file age in seconds: echo $(( `date +%s` - `stat -L --format %Y

How to use curl in a shell script?

心不动则不痛 提交于 2019-12-02 23:08:20
I'm trying to run this shell script in order to install RVM in an Ubuntu box #!/bin/bash RVMHTTP="https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer" CURLARGS="-f -s -S -k" bash < <(curl $CURLARGS $RVMHTTP) but I get the following error Syntax error: Redirection unexpected Also tested not using the variables, but same result, could you tell what I'm missing? Tilo #!/bin/bash CURL='/usr/bin/curl' RVMHTTP="https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer" CURLARGS="-f -s -S -k" # you can store the result in a variable raw="$($CURL $CURLARGS $RVMHTTP)"

Run bash script with sh

别等时光非礼了梦想. 提交于 2019-12-02 22:54:31
I have bash script and it requires bash. Another person try to run it with sh script_name.sh And it fails because sh is symbolic link to dash in his distribution. $ ls -la /bin/sh lrwxrwxrwx 1 root root 4 Aug 25 16:06 /bin/sh -> dash I have an idea to use wrapper script: #!/bin/sh bash script_name.sh The goal is to run .sh script by sh with bash in system having symbolic link to dash. Well, usually you use the shebang to tell the shell to use the correct interpreter: #!/bin/bash # your script here You have to set the script to be executable: chmod +x my_script.sh And let the user start it with

Is it necessary to specify traps other than EXIT?

最后都变了- 提交于 2019-12-02 20:12:06
I see a lot of shell scripts that do: trap cmd 0 1 2 3 13 15 # EXIT HUP INT QUIT PIPE TERM In every shell I have access to at the moment, all the traps other than 0 are redundant, and cmd will be executed upon receipt of a signal if the trap is simply specified: trap cmd 0 Is the latter specification sufficient, or do some shells require the other signals to be specified? Brandon Horsley I think trap 0 is executed just prior to script termination in all cases, so is useful for cleanup functionality (like removing temporary files, etc). The other signals can have specialized error handling but

When I use scp command through expect, asterisk can not recognized

主宰稳场 提交于 2019-12-02 18:57:53
问题 Hello I have a one problem in linux shell I write a scp script using expect and the script is like this. #!/bin/sh expect -c "spawn scp /tmp/data/*2017-06-14*.log2 id@localhost:~/"\ -c "expect -re \"password\" "/ -c "sleep 1" \ -c "send \"password\r\""\ -c "interact" and result of execution shows error message. /tmp/data/*2017-06-14*.log2 : No such file or directory But When not use expect, scp execution is success [user@localhost]# scp /tmp/data/*2017-06-14*.log2 id@localhost:~/"\ How can i