sh

Remove redundant paths from $PATH variable

邮差的信 提交于 2019-11-28 15:04:46
I have defined the same path in the $PATH variable 6 times. I wasn't logging out to check whether it worked. How can I remove the duplicates? The $PATH variable looks like this: echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/flacs/Programmes/USFOS/bin:/home/flacs/Programmes/USFOS/bin:/home/flacs/Programmes/USFOS/bin:/home/flacs/Programmes/USFOS/bin:/home/flacs/Programmes/USFOS/bin:/home/flacs/Programmes/USFOS/bin How would I reset it to just /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games You just execute: export PATH=/usr/local

What's a .sh file?

感情迁移 提交于 2019-11-28 13:53:31
问题 So I am not experienced in dealing with a plethora of file types, and I haven't been able to find much info on exactly what .sh files are. Here's what I'm trying to do: I'm trying to download map data sets which are arranged in tiles that can be downloaded individually: http://daymet.ornl.gov/gridded In order to download a range of tiles at once, they say to download their script, which eventually leads to daymet-nc-retrieval.sh : https://github.com/daymet/scripts/blob/master/Bash/daymet-nc

Argument list too long - Unix

隐身守侯 提交于 2019-11-28 13:31:48
This scripts will sort the files by date then move the first 2500 files to another directory. When I run below scripts, system prompt out Argument list too long msg. Anyone can help me enhance the scripts ? Thanks NUM_OF_FILES=2500 FROM_DIRECTORY=/apps/data01/RAID/RC/MD/IN_MSC/ERC/in DESTINATION_DIRECTORY=/apps/data01/RAID/RC/MD/IN_MSC/ERC/in_load if [ ! -d $DESTINATION_DIRECTORY ] then echo "unused_file directory does not exist!" mkdir $DESTINATION_DIRECTORY echo "$DESTINATION_DIRECTORY directory created!" else echo "$DESTINATION_DIRECTORY exist!" fi echo "Moving $NUM_OF_FILES oldest files to

Why does Scala use a reversed shebang (!#) instead of just setting interpreter to scala

时光怂恿深爱的人放手 提交于 2019-11-28 13:24:47
The scala documentation shows that the way to create a scala script is like this: #!/bin/sh exec scala "$0" "$@" !# /* Script here */ I know that this executes scala with the name of the script file and the arguments passed to it, and that the scala command apparently knows to read a file that starts like this and ignore everything up to the reversed shebang !# My question is: is there any reason why I should use this (rather verbose) format for a scala script, rather than just: #!/bin/env scala /* Script here */ This, as far a I can tell from a quick test, does exactly the same thing, but is

Bash script that executes php file every 5 seconds

微笑、不失礼 提交于 2019-11-28 11:44:26
问题 Bash script: $ cat test.sh #!/bin/bash while true do /home/user/public_html/website.com/test.php sleep 5 done Im trying to call it with cron: * * * * * /home/user/public_html/website.com/test.sh Where is my mistake? Does it matter where the .sh is located? EDIT: I fixed all the problems from above. I also created this cron job to prevent multiple proccesses: * * * * * flock -n /tmp/test.lock /home/user/public_html/website.com/test.sh The problem now is that the bash executes the php every 5

How to echo multi lined strings in a Bourne shell [duplicate]

怎甘沉沦 提交于 2019-11-28 11:01:57
This question already has an answer here: When to wrap quotes around a shell variable? 5 answers I want to create some scripts for filling some templates and inserting them into my project folder. I want to use a shell script for this, and the templates are very small so I want to embed them in the shell script. The problem is that echo seems to ignore the line breaks in my string. Either that, or the string doesn't contain line breaks to begin with. Here is an example: MY_STRING=" Hello, world! This Is A Multi lined String." echo -e $MY_STRING This outputs: Hello, world! This Is A Multi lined

Syntax error in sh - built and working for bash [duplicate]

落花浮王杯 提交于 2019-11-28 10:55:22
问题 This question already has answers here : initializing arrays in sh (2 answers) Closed 3 years ago . I just started learning bash and have a few scripts working together fine from the command line and via udev. However I just installed AT so I could get around some udev limitations. It's taken me forever to first notice that AT is very obvious about using sh - not bash , and that was causing my source command to fail. I since replaced it with the more portable . , that should work with all of

Print stdout in Python without shell escape sequences

这一生的挚爱 提交于 2019-11-28 10:15:05
问题 I'm using sh to run git commands inside a Python script. In [1]: from sh import git In [2]: s = git("log", "-1", pretty="format:%h %s") In [3]: print s 4f14a66 basic debug page This seems to work as expected. However, using this in a Django template gives [?1h= 4f14a66 basic debug page[m [K[?1l> . I tried to see what characters were in this string using repr() , to no avail: In [4]: print repr(s) 4f14a66 basic debug page It turns out commands in sh return a RunningCommand that has a .stdout

How to mark an array in POSIX sh?

会有一股神秘感。 提交于 2019-11-28 09:54:47
While replacing external commands in a shell script, I used an array to get rid of awk's NF . Now, since I moved from bash to POSIX sh, I cannot get the array marked right: #!/bin/bash export RANGE="0 1 4 6 8 16 24 46 53" RANGE=($RANGE) echo arrayelements: $((${#RANGE[@]})) LAST=$((${#RANGE[@]}-1)) echo "Last element(replace NF): ${RANGE[$LAST]}" # ./foo arrayelements: 9 Last element(replace NF): 53 I'm using OpenBSD's, sh and it has exactly the same size as the ksh. Changing above to /bin/sh , it seems that the following doesn't work: set -A "$RANGE" set -- "$RANGE" How could I realise the

How do I turn off echo in a terminal?

∥☆過路亽.° 提交于 2019-11-28 09:50:29
I'm writing a Bourne shell script and have a password input like this: echo -n 'Password: ' read password Obviously, I don't want the password being echoed to the terminal, so I want to turn off echo for the duration of the read. I know there's way to do this with stty , but I'll ask the question for the benefit of the community whilst I go read the manpage. ;) stty_orig=`stty -g` stty -echo echo 'hidden section' stty $stty_orig read -s password works on my linux box. You can use '-s' option of read command to hide user input. echo -n "Password:" read -s password if [ $password != "..." ] then