New answers tagged

0

This answer should be quite safe with regards to whitespace. But perhaps it is bash-specific? It inserts -regextype posix-extended in front of the first -iregex or -regex. Save this somewhere in your $PATH. And, if you save this as find, make sure you edit the last line (find "$@"), otherwise it will just call itself in an infinite loop #!/bin/bash for ((i=...


0

Divide in sub-problem In general when you cannot find a fast complete solution to your problem you can divide it in sub-problems more easy to be solved. A way is to create a tar file of the directory structure and a list of files to be touched inside the directory structure that you can compress after. You do not need to create the whole directory ...


1

It's actually easier for the implementer to not have to worry about this. When doing a pipe each component is run in its own subshell (except maybe the first in bash, or the last in ksh88/ksh93 if the command is a native one). Thus the function definition in the middle of a pipeline would be defined for the shell instance for that component of the pipe, ...


4

Why wouldn’t it be possible? Is it pointless? Definitely. But it works: $ function asdf { echo "bla"; } | hexdump -C; echo EOF EOF Similarly: $ function asdf { echo "bla"; } | asdf | hexdump -C; echo EOF -bash: asdf: command not found EOF Defining a function is a “command” like any other. It doesn’t have any output and doesn’t take any input, though. ...


1

I thought of using the -exec option for find but this would not work due to the redirection operator used with the gunzip command. One solution would be to perform the operation in two steps: 1. Copy the archives into $NEWDIR: while read line do find "$PARENTDIR" -name "$line*" -exec cp -v {} "$NEWDIR" \; done < "$LIST" This should ...


0

Using awk: $ echo '[10/04/16 01:02:03 BST]' | awk -F'[][/: ]' 'BEGIN{split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",m,/ /)} {print m[$3+0],$2,$4,$5":"$6":"$7}' Apr 10 16 01:02:03 How it works -F'[][/: ]' This sets the field separator to any of [, ], /, :, or blank. BEGIN{split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",m,/ /)} This ...


4

Try: find . -mindepth 2 -type f -name '*.pdf' -exec bash -c 'f=${1#./}; mv "$1" "./${f//\//_}"' None {} \; This is safe for all file names, even ones with newlines in their names. How it works -mindepth 2 This tells find not to process any files that are already in the current directory. -type f -name '*.pdf' This restricts the search to regular ...


0

This is as close as I could get zipinfo -1 A.zip | xargs -l sh -c ' unzip A.zip "$0" && zip -9 A.zip "$0"; rm -f "$0" ' Which only ever creates one tmp file for each file in the zip at a time. If I can find a way to zip from stdin and pass a filename I'll be able to use unzip's -p to use pipes all the way instead. zipinfo -1 A.zip | ...


0

You can check if a custom variable has been set, otherwise set it and then add the new entries: if [ "$MYPATHS" != "true" ]; then export MYPATHS="true" export PATH="$PATH:$HOME/bin:" # java stuff export JAVA_HOME="$(/usr/libexec/java_home)" export M2_HOME="$HOME/Applications/apache-maven-3.3.9" export PATH="$JAVA_HOME/bin:$M2_HOME/...


0

Bash follows Posix conventions and on startup first sets your shell context by sourcing the /etc/profile file. On RedHat systems, the /etc/profile file contains code to look into /etc/profile.d for files ending in '.sh'. It then sources each of them one-by-one, adding the variables set therein to your environment. Likewise, the csh/tcsh shells run /etc/csh....


0

In a DOS window, you can send all of your environment variables into a batch file and run that to change the variables for the duration of that session: C:\temp> set >newenv.bat Click back into windows and pull the newenv.bat file up in your favorite editor and delete all of the variables except the ones you want to reset. For the ones left, add the word '...


0

SET variable=string Variable is the new variable you want to create (or an existing one) String is what you want to assign to variable Example of storing a text string: C:> SET _dept=Sales and Marketing Source: http://ss64.com/nt/set.html NOTE: Changes made with SET will only remain for the CMD session.


0

Have you tried wget --nc? -nc, --no-clobber: skip downloads that would download to existing files. (http://stackoverflow.com/questions/4944295/skip-download-if-files-exist-in-wget)


1

I use xssstate for such purposes. It's available in suckless-tools package in Debian or Ubuntu, or upstream. Then you can use the following shell script: #!/bin/sh if [ $# -lt 2 ]; then printf "usage: %s minutes command\n" "$(basename $0)" 2>&1 exit 1 fi timeout=$(($1*60*1000)) shift cmd="$@" triggered=false while true do tosleep=$(((...


-1

bsd ports (packages collection) has a program that can do this: http://man.openbsd.org/OpenBSD-current/man1/xidle.1 it's available e.g. here: http://distcache.freebsd.org/local-distfiles/novel/xidle-26052015.tar.bz2 build like: # apt-get install libxss-dev # for include/X11/extensions/scrnsaver.h # gcc -o /usr/local/bin/xidle xidle.c -lX11 -lXss note ...


0

Start session startup and run in detached window command1 Add new detached window and run command2 screen -dmS startup bash -c 'command1; exec bash' screen -S startup -x -X screen bash -c 'command2; exec bash' Reattach the sessionstartup at any time screen -r startup


1

Here documents with an unquoted delimiter undergo variable expansion. Therefore, $! is interpreted in the context of the outer script, not the shell that runs the commands from the here document. Either quote the << 'EOBLOCK', or backslash the dollar signs in the here document: kill \$!.


0

I had the same problem in Arch Linux using zsh. Using bash everything works just fine, but when I switch to zsh some characters were displayed wrong (e.g. ñ,°). I've added export LANG="en_US.UTF-8" to my .zshrc and nothing happened. I did everything to set LANG inside zsh and nothing fixes. Then I changed my shell back to bash with chsh -s /bin/bash ...


3

I have a possible theory for this. When you run the application as $ rake resque:work QUEUE='*' & [1] 13031 The application internally does a fork+exit, to run in background. C code equivalent of that would be: if(fork()) exit(0); So, the process with PID==13031 will spawn a child process & exit itself. The child will keep running in ...


2

First, you should almost never use ${ARRAY[*]}, either with or without quotes. In almost all situations, you should use "${ARRAY[@]}" (with the double-quotes) instead. Second, you should use lowercase or mixed-case variable names to avoid accidentally using a name that means something special to the shell or one of the programs you run from it. Now, for ...


0

The problem with your code, I believe, is most likely the calculation of STEM. Its not immediately clear to me the format that your files are in or how you are going to group them, but try something like: # Find files created within date range: fromdate="201606010000" todate="201606302359" touch -t $fromdate /tmp/fromdate.del touch -t $todate /tmp/todate....


0

Assuming you do not know which logs contain June: zcat *gz | grep Jun > junelog


1

Let's assume your in your directory the presence of the files 1.a,2.a,3.a. With the command ls *.a | xargs -I{} echo {} | sed 's/.a//' you have no subshells, the output of ls is piped in xargs that make its substitutions. Then the output is piped to sed. From here your first result. With the command ls *.a | xargs -I{} bash -c "echo {} $(echo {} | ...


1

The difference between running the script via systemd and running it directly it directly is the environment. You can test it like this. In your Unit file, add this to the [Service] section, for testing: StandardOutput=console Then in your bash script, at the top add this line to dump the environment: env Now run the script inside and outside of ...


1

I think you can try this: ssh user@host -t 'export var="value"; bash'


0

It now works when I change both the CATALINA_HOME and CATALINA_BASE to: #CATALINA_HOME is the location of the bin files of Tomcat export CATALINA_HOME=/users/tomcat/apache-tomcat-8.0.30 #CATALINA_BASE is the location of the configuration files of this instance of Tomcat export CATALINA_BASE=/users/tomcat/apache-tomcat-8.0.30 So the entire script that ...


1

The issue with your sed command $ sed '/^[a-z]\+=/,+0d' testfile.txt is that the sed script is applied to every line of the input data. The +0 (which is a GNU extension) means that your script is equivalent to $ sed '/^[a-z]\+=/d' testfile.txt and the first and second lines would be deleted, as you noticed. Incidentally, you will get exactly the ...


0

I was able to get this to work using a virtual frame buffer: sudo apt-get install xvfb -y xvfb-run firefox -CreateProfile default


0

I found a solution, although not an ideal one After renaming all my bash scripts to have a .sh extension, Spotlight starts indexing them as kMDItemContentType = 'public.shell-script' This at least means it can be picked up by Alfred


0

Create a script as below: # !/bin/bash read -p "Enter target server IP : " server echo "Enter root password for $server : " ; read -s password yum install sshpass -y sshpass -p "$password" ssh -o strictHostKeyChecking=no root@$server echo "your text goes here" >> /remotefile.txt


0

I'm not sure if I understood what you need. Please tell me if the following code doesn't solve your problem. # !/bin/bash echo "Please enter a number." read NUM while read -n1 DIGIT; do echo "Digit: $DIGIT" while true; do RND=$((RANDOM%10)) if [[ "$RND" == "$DIGIT" ]]; then echo "$RND matches."; break; ...


0

$sort -k2 file "TTTTCTTCTA" 1 "TTTTCTTCCT" 2 "TTTTCTTACC" 1 "TTTTCTTATT" 2 "TTTTCTTCGG" 2 2 "TTTTCTTCTG" 1 "TTTTCTTGAA" 1 "TTTTCTTACA" 1 1 "TTTTCTTTAG" 1 1 "TTTTCTTTGG" 1 ...


2

tl;dr sort -k1.5 file | uniq -s 6 -w 5 Explanation My sort is GNU coreutils 8.22. The manpage for my sort shows: KEYDEF is F[.C][OPTS][,F[.C][OPTS]] for start and stop position, where F is a field number and C a character position in the field; both are origin 1, and the stop position defaults to the line's end. So with your ...


0

It works for me, but if I change the line termination to DOS style (CR/LF line termination) $ u2d ./prova.sh unix2dos: converting file ./prova.sh to DOS format... $ ./prova.sh Hello ./prova.sh: line 10: syntax error: unexpected end of file so convert your script to unix style (LF as line end) $ d2u ./prova.sh dos2unix: converting file ./prova.sh to ...


0

Figured out an answer for the rest of internet (and myself). Here's how to achieve port forwarding with only netcat (verified working on OS X El Capitan): On server behind (incoming) firewall: nc localhost 22 >& /dev/tcp/<your-hostname>/<open port on local computer, i.e. 9000> 0>&1 On local computer: cd /tmp; mkfifo backpipe ...


2

Perl to the rescue: echo one-two-three-four-five | perl -pe 's/-(.)/\u$1/g' \u upcases the following character.


1

@John1024 I'm sorry but your solution works only if the first matching line is the first line of the file. I solved the problem with the following code sed -r '0,/^[a-z]\+=/{//d;}' testfile.txt but I'm still convinced that my previous solution should have worked even with posix sed. Infacts the idea was to give as second line address an offset of 0 lines......


0

Using the ssh configuration file is also a valid option. Here's what you can put/add to your ~/.ssh/config file: Port 10022 Cipher des You can also filter these parameters by remote host by prepending these lines with Host xyz.domain.whatever and indenting them: Host 192.168.1.15 Port 10022 Cipher des


1

Binding ctrl+enter doesn't make any sense. The enter key normally sends a carriage-return; \r, aka \cM. In other words, enter is already a control character. So applying the \c modifier does’t make any sense. In fact, this should cause Fish to generate an error so I’ll open an issue to remind the team to fix that. Also, you were trying to bind \c\n. Binding ...


0

You need to remove src/xsum, an executable for the wrong architecture. The Makefile will automatically build it again. I found this by stepping through install_f2c_osx.csh manually. In the src subdirectory make produced: make ./xsum Notice README cds.c data.c defines.h defs.h equiv.c error.c exec.c expr.c f2c.1 f2c.1t f2c.h format.c format.h ...


0

Well...I feel dumb. But I'll answer this question for anyone else having the same problem. Since I'm developing on a Windows computer, it's using CRLF line endings. I use Sublime Text and never think about line endings because I'm always developing for Windows. But, of course, bash scripts need to use LF line endings, or else weird stuff happens. I couldn'...


2

Use the full path to rm; confirm that its the same on your system: /usr/bin/rm -f /var/run/memcached/memcached.pid init scripts do not have your ( or roots) PATH environment variable set typically.


0

I think rc.local environment during startup isn't rich. If it knows any $PATH and $HOME (shell expands ~ to $HOME) they are not your (regular user's) variables; I think they may be unset. Furthermore the script will inherit this limited environment. However when you do sudo /etc/rc.local or sudo ~/bin/session.sh the command inherits your environment and all ...


0

With ConEmu 160207 (on a Windows7 Pro), after installing Docker (version 1.11.1, build 5604cbe) and then bring up a ConEmu windows, I noticed there is a task for Docker automatically added. Here's the ConEmu setting dialog box:


0

To the best of my knowledge, no, there is nothing exactly like that in Os X. Ionice is a strictly-Linux command, it does not exist in Unix, which makes it unlikely it exists in Os X either. To make sure, the list of commands unique to OS X does not mention ionice. Also, the FreeBSD online manual does not mention any special capability for either nice, ...


0

Two things I've learned when debugging bash commands: One) If it's not working like you think it should, echo/printf out the commands to ensure they display the way you think they should. Two) Manually run the commands you have within your commands to see if they run properly, (unless these are potentially destructive commands, such as: rm, dd, chmod 777, ...


0

This doesn't need a 'coded solution.' If you sort the lines first, the algorithmic complexity is reduced by several orders of magnitude. See this answer for better performance, both in terms of CPU time and memory: https://stackoverflow.com/questions/4366533/remove-lines-from-file-which-appear-in-another-file


0

the permissions for the file are wrong. Try the following commands: $ chmod 777 file.sh $ ./file.sh


0

Eventually I made some tweaking to my script so that it essentially runs continuously and starts logging when it loses connection, instead of looking for a lost connection: https://github.com/NobleUplift/NetCheck But really, we just needed to switch ISPs.


0

Until they get this worked out, I installed cygwin sshd for visibility to the native NTFS file system and ran the ubuntu sshd for visibility to the lsxx linux files. use apt-get to install sshfs and win-sshfs to do mounts each way. It is a round-about hack but works for me for now. If you didn't want to mess with the cygwin sshd, you could use cygwin ssh to ...



Top 50 recent answers are included