Tag Info

New answers tagged

0

zsh's jobs builtin can change the shell's process name. jobs -Z newname


0

You could make your script recursive this way: #! /bin/sh - do-something-with "$1" shift [ "$#" -eq 0 ] || exec "$0" "$@" Then when running your-script a b c, the ps output would show in turn: your-script a b c your-script a b your-script a


0

Try this way: #!/bin/bash sudo sh /opt/scripts/runp.sh & sudo sh /opt/scripts/runt.sh & sudo sh /opt/scripts/rund.sh & ssh sut@slave sudo sh /opt/scripts/runs.sh & ssh sut@slave /home/sut/pf/server-sysfs 8989 & sudo sh /opt/scripts/runc.sh &


0

Credit goes to St├ęphane Gimenez but if someone would like to display seconds only if a period is less than a minute here is my modified version that I use (also with fixed pluralization): converts() { local t=$1 local d=$((t/60/60/24)) local h=$((t/60/60%24)) local m=$((t/60%60)) local s=$((t%60)) if [[ $d > 0 ]]; then ...


0

Did it. $ vboxmanage registervm ~/VirtualBox\ VMs/origClone/origClone.vbox


2

You don't specify whether you also want the files in any subdirectories of /group/book/four/word. The find solution in jherran's answer will descend into subdirectories. If that is not wanted, use the shell instead: for file in ./*; do [ -f "$file" ] && wc -l "$file"; done | sort -n If your file names can contain newlines, you can use something ...


3

With zsh: lines() REPLY=$(wc -l < $REPLY) printf '%s\n' /group/book/four/word/*(.no+lines) We define a new sorting function lines that replies with the number of lines in the file. And we use the o+lines glob qualifier which together with n (for numeric sort), defines how the results of the glob are ordered. (. also added to only check regular files). ...


5

You should use a command like this: find /group/book/four/word/ -type f -exec wc -l {} + | sort -rn find : search for files on the path you want. If you don't want it recursive, and your find implementation supports it, you should add -maxdepth 1 just before the -exec option. exec : tells the command to execute wc -l on every file. sort -rn : sort the ...


0

I just made a discovery: How can I launch applications from 2 ttys on launch? One of the comments mentions something called openvt. This command appears to do the exact thing I'm after! http://linux.about.com/library/cmd/blcmdl1_openvt.htm Unless anyone knows different, I think this is probably the "correct" way to do this. (I just tried it, and it ...


1

You should always avoid mixing languages as much as possible. In this case you are trying to mix shell script into ruby script. Mixing languages convolutes your code and makes it fragile. The solution in this case is to use ruby's native environment variable support. $ GHREPO=ecx ruby -rjson -e 'j = JSON.parse($stdin.read); puts ...


0

In case sed does not support reading of a script from stdin (using -f -), you can use process substitution (available in bash, zsh, ksh93): sed "$IN" > "$OUT" -f <( cat << SED_SCRIPT s/a/1/g s/test/full/g SED_SCRIPT) The closing parenthesis ) must follow the end delimiter (SEC_SCRIPT) immediately or after a newline. In the case of ...


0

It should be '"'$GHREPO'"' so the command is cat dummy.json | ruby -rjson -e 'j = JSON.parse($stdin.read); puts j["ChgSub"]['"'$GHREPO'"'][0]["Major"].to_s' @Etan was pretty close to the answer.


2

This is the solution that will work for your case. Break your script into functions, and each time a function is called you source it from a separate file. Then you could edit the files at any time and your running script will pick up the changes next time it gets sourced. foo() { source foo.sh } foo Testing I have created 2 scripts say callee.sh ...


-1

Maybe a nicer approach: OUT=/dev/stdout IN=my_in_file.txt sed -s 's/in/out/' < $IN > $OUT -or- sed -s 's/in/out/' > $OUT < $IN IN=my_in_text sed -s 's/in/out/' <<< $IN > $OUT -or- sed -s 's/in/out/' > $OUT <<< $IN :)


3

Variables don't get evaluated in a single quoted string. You need to use double quotes. If you can't or don't want to use double quotes for the whole string you can use them for just that part of the string. ruby -rjson -e 'j = JSON.parse($stdin.read); puts j["ChgSub"]["'"$GHREPO"'"][0]["Major"].to_s' That is three separate quoted strings next to one ...


2

That is because a starting X session never reads your ~/.bashrc and ~/.profile. Usually, the desktop manager is started as root or its own user from an init script. The resulting process usually has the environment of the init process when it hits the desktop manager starting script. (I will not talk about less established init implementations at this ...


0

I tend to do something like this: if ! which dos2unix > /dev/null; then echo "Error: dos2unix not installed!" exit 1 fi


1

Yes, it is possible. Use: $ vboxmanage showvminfo testvm | grep VRDE: VRDE: enabled (Address 0.0.0.0, Ports 3398, MultiConn: off, ReuseSingleConn: off, Authentication type: null)


0

There is a clever trick with tee and subshells: cat source.lst | tee >(doSomething.sh) >(somethingElse.sh) | somethingFinal.sh I've done this before pv -perl source.list | tee >(doSomething.sh) >(somethingElse.sh) | md5sum pv will give you a progress bar, an ETA, and a running line total. Then source.lst will be fed to doSomething.sh and ...


3

It's not possible in general, because a script can contain something like read $command "$command" -rf / In real life, the command would be sanitized or picked from a list, but still, it's not possible to know in advance what commands are possible.


0

Try doing this explicitly : test_apps="command1 command2 command3" for cmd in $test_apps; do type &>/dev/null $cmd && echo "$cmd installed" || echo >&2 "$cmd not installed" done Or if you put your commands with full PATHs : grep -oP '^\s*/.*/\K.*' script.sh | xargs -I% which % 2>&1 | grep -oP ...


9

setsid sh -c 'exec command <> /dev/tty2 >&0 2>&1' As long as nothing else is using the other TTY (/dev/tty2 in this example), this should work. This includes a getty process that may be waiting for someone to login; having more than one process reading its input from a TTY will lead to unexpected results. setsid takes care of starting ...


1

It should also report -bash: [: missing `]' or -bash: [0: command not found Insert whitespace where needed. In bash, [[ ... ]] conditions are generally easier to use than [ ... ].


5

On the second tty there will be normally a program running, either some login program or some shell like bash. If you want interaction you either would have to replace the login program with yours, or tell a shell to run the program as if the program was started from the commandline. A more simple solution, IMO, would be to start a tmux session after ...


7

Just put a space and the comment character # at the end of the alias string: alias ftp='echo do not use ftp. Use sftp instead. #' ftp abcd.com do not use ftp. Use sftp instead. This will cause the parameters to be treated as a comment. Just do not forget to add a space before # otherwise it will not be interpreted as a separate token after the alias ...


14

When you define an alias, the command you set is run instead of the one you wrote. This means that when you run ftp abc.com, what is actually executed is echo do not use ftp. Use sftp instead abc.com A simple solution is to use a function instead of an alias: ftp(){ echo 'do not use ftp. Use sftp instead'; } Alternatively, you could use printf as ...


12

alias ftp='echo do not use ftp. Use sftp instead. # '


1

find . -type f | xargs sed -i 's/abc/xyz/g' Use -maxdepth option if you don't want the action to take place recursively in your current working directory.


0

Python In python i would do like the below, #!/usr/bin/python import re import sys file = sys.argv[1] with open(file, 'r') as f: for line in f: print ' '.join(re.findall(r'(?<!\d)\d{4}(?!\d)', line)) Save the above script as script.py and then run it by applying the below command on the terminal. python script.py file Example: $ cat ...


2

#!/bin/bash unset u mnt() { ${u+u}mount /ip/share1 ${u-"/local/share1"}; } case "$1" in (-mount) :;; (-umount) u= ;; (-restart) u= mnt ;; (*) ! :;; esac && mnt You could use a function as ^above^.


0

As @Mat shows in his answer, a SIGSPEC of 0, when used on the trap command will cause the trap command to run when the script exits. This example illustrates what happens. $ cat tr.bash #!/bin/bash echo "PID: $$" trap 'echo hi; exit 1' 0 1 2 15 while [ 1 ]; do sleep 3 done When we run this: $ ./tr.bash PID: 24086 It sits here waiting ...


3

It looks to me like that should work, other than the syntactical quibble of missing )s. I tested this and it behaves correctly.. #/bin/bash case "$1" in "-mount") mount /path/to/device /path/to/mountpoint ;; "-unmount") umount /path/to/mountpoint ;; "-mount") "$0" -unmount "$0" -remount ;; *) echo "You have failed to ...


1

With a single s/// you can do this in a POSIX sed - but there are a lot of backslashes: sed 's/[^0-9]*\([0-9]\{5,\}\)*[^0-9]*\([0-9]\{4\}\)*.\{0,1\}/ \2/g ' <<\IN 92828 Hello 8473 World War 1 1914-1918 Hello 8391 World War 2 1939-1945 IN OUTPUT 8473 1914 1918 8391 1939 1945 It globally gobbles all of the sequences with 5 or more digits first - ...


0

with gawk echo '9228 Hello 8473 World War 1 1914-1918 Hello 8391 World War 2 1939-1945' | awk --re-interval -v RS='\\y[[:digit:]]{4}\\y' '{printf "%s ", RT}END{print ""}' 9228 8473 1914 1918 8391 1939 1945


4

You can use perl. perl -nle'print join " ", /(?<![0-9])[0-9]{4}(?![0-9])/g' This also works for multi-line input, so if you have: 9228 Hello 8473 World War 1 1914-1918 Hello 8391 World War 2 1939-1945 You'll get the following returned: 9228 8473 1914 1918 8391 1939 1945 (Add -0777 if you want the numbers on the same line.)


2

With perl: $ perl -Tnle 'BEGIN {$, = " "} print $_ =~ /\b\d{4}\b/g' file 9228 8473 1914 1918 8391 1939 1945


3

POSIXly: < file tr -cs 0-9 '[\n*]' | grep -xE '.{4}' | paste -sd ' ' -


7

I can answer with grep command: Input file: 9228 Hello 8473 World War 1 1914-1918 Hello 8391 World War 2 1939-1945 Command: grep -Eo '\<[0-9]{4}\>' file |tr '\n' ' ' Return any number with length=4. -E switches to extended regex -o print only the matching part Output: 9228 8473 1914 1918 8391 1939 1945 Update answer: Input file: 9228 ...


1

It's a confusing question with the paths and su'ing. When you run this command: $java -cp ./classes:./lib com.mystuff.bar.foo.myclass And get 'class not found', that means java is not able to find that class in ./classes or ./lib. If you either a) use absolute paths, or b) cd to the right place before running the command (su scriptuser -c "cd $home ; ...


0

$? gives you the status of last executed command:called as exit status if success its 0 else can be any number root@hackaholic:~# echo "hello" hello root@hackaholic:~# echo $? 0 root@hackaholic:~# ps PID TTY TIME CMD 21005 pts/2 00:00:00 bash 21051 pts/2 00:00:00 ps root@hackaholic:~# echo $? 0 root@hackaholic:~# junk bash: junk: command not ...


1

For displaying the current directory bash keeps some internal state that doesn't necessarily corresponds to the actual (shortest) path to the current directory. This helps in keeping the path if you cd through soft links. The cd // (but also when doing e.g. cd //tmp) do not seem to trigger a sanitization of the internal path displayed by pwd, but more than ...


1

Another alternative (piping two tr commands): ls -l partition | cut -c5-7 | tr -dc rwx | tr rwx cse


2

The problem is: When bash is started non-interactively then it does not read ~/.bashrc. Thus you have to read h() from the script. If you want to use aliases in a script then you have to enable the use of aliases in the script with shopt -s expand_aliases define the alias in the script. An alternative to an alias is defining a shell function (which ...


0

You seem to have several problems. The free-standing backslashes (\) should be removed. You may use backslashes at the ends of lines to continue commands onto continuation lines; e.g., command1 \ command1 args \ command1 continued # No backslash on last line command2 \ command2 args \ ...


3

All the processing done by SLURM (by sbatch, specifically) is done before bash is invoked, so bash won't help you here. The script could be in any language, it wouldn't matter: the #SBATCH are only coincidentally bash comments, what matters is that they're sbatch directives. Options can be specified in the file so as to provide a convenient way to always ...


2

Alternative way without ls: getfacl -c partition | sed -n '/group::/{s/.*:://;y/rwx/cse/;s/-//g;p;}'


3

I think you want this command: ls -l partition | cut -c5-7 | tr rwx cse |sed 's/-//' You can remove the one extra command(cut -d ' ' -f 1) and replace it with your last cut command(cut -c5-7) and also add sed 's/-//' at the end to remove all -s. Now you are done. you didn't need to adding extra |. And even better: you can also change the dash(- ...


0

Figured it out. Here is my functional script: #!/bin/bash ADMIN_PASS="$(cat /Users/adminuser/Documents/UpdateScript/enPass.txt)" ADMIN_USER="adminuser" HOST_LIST="/Users/adminuser/Desktop/hosts.txt" for HOST in $(< $HOST_LIST); do echo "" echo "--------------------------------" echo "# CONNECTING TO: $HOST #" echo ...


0

You have some missing pieces of your paths it looks like. On top of that, it's just plain messy code. Good code should be clean and easy to read. You have way too many '/'s in your example. Clean that up, and it will be easier to see where the differences are. In the first command: nohup java -Xmx3g -jar GenomeAnalysisTK.jar -T RealignerTargetCreator ...


1

I would use sed it's really powerfull, this bash file would change the values: #!/bin/bash path_to_conf="/path/to/vsftpd.conf" anonymous_=NEIN local_=JA chroot_=IDK sed -c -i "s/\("anonymous_enable" *= *\).*/\1$anonymous_/" $path_to_conf sed -c -i "s/\("local_enable" *= *\).*/\1$local_/" $path_to_conf sed -c -i "s/\("chroot_local_user" *= ...



Top 50 recent answers are included