spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » BASH » Page 1
Add stdin as another file to a tar archive
I don't know a way to create a "fake" file entry in a JAR archive. I'd create a normal file, add it to the archive and then delete it afterwards. You may want to try the option -A (or --concatenate), though. That would allow you to create the file in /tmp, add it to the TAR archive and then append the rest of the files in a second step. That way, you can create arbitrary paths for the VERSION fil

Categories : Bash

Sum of all rows of all columns - Bash
You want to sum every column differently. Hence, you need an array, not a scalar: $ awk '{for (i=1;i<=NF;i++) sum[i]+=$i} END{for (i in sum) print sum[i]}' file 6 15 24 This stores sum[column] and finally prints it. To have the output in the same line, use: $ awk '{for (i=1;i<=NF;i++) sum[i]+=$i} END{for (i in sum) printf "%d%s", sum[i], (i==NF?" ":" ")}' file 6 15 24 This uses the tr

Categories : Bash

I'm having an error while "gem uninstall rails"
change permissions for yourself: $ sudo chown $(whoami):$(whoami) /usr/local/rvm/gems/ruby-2.0.0-p481/ -R then try removing rails again: $ gem uninstall rails

Categories : Bash

what should be the if condition for separating big files during copy process?
Remove -exec du -sh {} ; from your command as it is adding size of file as well. Use -type f to select only files as below: bigfile=$(find . -type f -size +5G)

Categories : Bash

awk script to print in between result before the final result
I would go for something like this: awk 'NR==1 {next} {a[$1]+=$2} END {for (i in a) {print i, a[i]; tot+=a[i]} print "TOTAL", tot}' file For your given input it returns: 20140201 -362.9 20140202 -210 20140203 132 TOTAL -440.9 Explanation NR==1 {next} skip the first line. {a[$1]+=$2} for every line, keep an array containing a[day]=value. END {} when finished, print the

Categories : Bash

Is it necessary to quote command substitutions during variable assignment in bash?
The shell does not perform word splitting for variable assignments (it is standardized that way by POSIX and you can rely on it). Thus you do not need double quotes (but you can use them without making the result different) in variable=$(command) # same as variable="$(command)" However, word-splitting is performed before executing commands, so in echo $(command) echo "$(command)" the resul

Categories : Bash

Spliting specific word out in sentence in BASH and AWK?
Simple string substitution will do: #!/bin/bash path=/home/test/kernel/drivers/middle/sdk/build/linux/src/soc/phy/test.c ffname="${path##*/}" # filename component echo "newpath: ${path///build*/}/${ffname}" output: newpath: /home/test/kernel/drivers/middle/sdk/test.c

Categories : Bash

Choosing directories to output by timestamp named directories
Assuming these directories in a file like shown you can use this awk: awk -F_ -v s1='20141123-0437' -v s2='20141124-0440' 'BEGIN{ split(s1, a, "-"); split(s2, b, "-"); start = a[1]a[2]; end = b[1]b[2]; } int($2$3) >= start && int($2$3) <= end' file /d_20141123_0437 <--- start /d_20141123_0438 /d_20141123_0439 /d_20141123_0440 /d_20141124_0438 /d_20141124_0439 /d_201

Categories : Bash

sed remove first two characters if some string existed
You could simply use sed like below, sed 's/^b.//' file Explanation: ^ Asserts that we are at the start. b Matches a literal b . Matches a literal dot. Replacing the matched characters with an empty string will give you the desired output.

Categories : Bash

what does this strange little yellow arrow below the command prompt mean?
It's almost certainly your PS2 prompt, used for line continuation. For example, I have PS1 set to 'pax> ' and PS2 set to '...> ' and the following transcript shows that in action: pax> echo 'hello ...> there' hello there The reason the PS2 prompt is there is because you have an unterminated " character (though, technically, this is an unstarted quote but the shell isn't smart enough

Categories : Bash

Windows batches in Cygwin with spaces in path and arguments
$ echo "echo %~1" > /cygdrive/c/te st/win.bat $ cat /cygdrive/c/te st/win.bat echo %~1 $ cmd /c $(echo "c: e stwin.bat"| sed 's/ /^ /g') "aaa bbb" C:UsersMe>echo aaa bbb aaa bbb

Categories : Bash

Tree hiearchy in Bash
There are quite a few issues with that code. The most serious is that your variables are not made local (see help local) which can be disastrous in a recursive function. In the loop in drawtree, the second iteration will see unwanted modifications to $depth and $lines, both of which will cause the output to be incorrect in different ways. Also: g=$(($depth-1)) l="$lines----" if [[ $g > 00 ]]

Categories : Bash

How to redirect the output of time command to a log file?
time command is shell keyword... when your run time command in terminal it's not /usr/bin/time so the options like -a and -o will not work with time command. However man time will still display man page of /usr/bin/time .You have to use /usr/bin/time -o logfile command to redirect the time's output to file logfile or you can use the following command which is similar to shell's keyword time: /u

Categories : Bash

Change files format from '.less' to '.scss'
You could try the below find command on the directory where the files you want to rename are stored. find . -type f -name "*.less" -exec rename 's/.[^.]*$/.scss/' {} ;

Categories : Bash

Interleave two wildcard commands
Your paste attempt was pretty close. I think the problem was just that paste expects lines and you weren't splitting the inputs into lines. Try this: $ ls a.cpp.pdf b.h.pdf d.cpp.pdf r.cpp.pdf s.h.pdf a.h.pdf c.cpp.pdf d.h.pdf r.h.pdf t.cpp.pdf b.cpp.pdf c.h.pdf main.cpp.pdf s.cpp.pdf t.h.pdf $ echo $(paste <(echo *.h.pdf | tr ' ' ' ') <(echo !(main*).cpp.pdf |

Categories : Bash

Multiple options for the same `case` result in `bash`
) symbol is just a delimiter for a specific case pattern, so --one ) || -o ) isn't right. Instead just provide a list of patterns separated by | symbol: case "$1" in --one | -o ) echo "one" ;;

Categories : Bash

Bash - default size in printf
Because of the way bash interprets command lines, double-quotes are needed around any argument that might either (a) be empty or (b) contain whitespace. Try: $ printf "%3s%3s end " "$bar" "$foo" foo end Explanation Without double quotes around it, an empty shell variable is not kept as an empty argument; it is simply removed from the command line. For example, consider: $ printf "%3s%3s

Categories : Bash

Shell Scripting: awk not printing local variables correctly
You cannot use shell variable as such in awk use -v to pass the value to awk variable as awk -v random=$random '{printf("%d%0.5d ", $0,random )}' -v random=$random creats an awk variable random and passes the sets it with the value of shell variable $random Test $ cat test #!/bin/bash year_start=1900 year_end=2014 for(( year=$year_start; $year <= $year_end; year=`expr $year + 1` )) do

Categories : Bash

Files in docker container disappear
I think I found the problem. It is not related to Docker at all. It's a bash thing. When invoking: docker run -it --name gen_skeleton_cont mailman_server ls /etc && echo "Second ls:" && ls /etc The first ls happens inside the Docker container, however the second one happens inside the host machine. I should find some other way to run mu

Categories : Bash

Argument grouping in bash scripts
You can use quotes to prevent this. Examples : test() { for i in "$@" do echo "$i" done } test "$@" Output : $ ./test.sh foo "bar baz" foo bar baz Without quotes : test() { for i in $@ # no quotes do echo "$i" done } test "$@" Output : $ ./test.sh foo "bar baz" foo bar baz Or test() { for i in "$@" do echo "$i" done

Categories : Bash

Inquire in fortran 90
The INQUIRE is not a function, it is a statement. Fortran standard doesn't have any notion of directories, so it depends on the operating system and the compiler, where it has access to. In practice it looks in the current directory. You can also use absolute path, of course.

Categories : Bash

How to write a decimal for loop in bash
In short, you "can't," in the sense that the Bourne shell doesn't "do" floating-point math. You can, however, use another scriptable tool, like Perl, to do it for you: $ver = $(perl -e "print $ver + .01") see also bc, awk, or other tools.

Categories : Bash

Copy and Delete
Most of what you're doing looks like shotgun debugging attempts—just changing random things without really knowing what they mean. You should really read through a tutorial on find, and maybe one on bash scripting. Anyway, you can string together multiple actions on a single find command. Even multiple -exec actions if you want. So: find . -type f -mtime +30 -exec cp --parents '{}' /home/me/

Categories : Bash

Sed and UTF-8 encoding
You have to ensure that the issued sed command is UTF-8 encoded. You can do this in one of two ways: Write the sed command to a file, ensure the file is UTF-8, and execute it as a script: file yourfile should say UTF-8 Unicode text. You can then run bash yourfile. Alternatively, change your terminal and shell settings to UTF-8 printf à | wc -c must say 2, not 1. locale should list "UTF-8

Categories : Bash

Removing part of a line? [bash]
inputs to cut need some reformatting. Use cat /proc/$1/cmdline | cut -d -f 1 Mind ya, there is a space after the backslash. BTW I see you asked "What is the easiest way to remove '--type=zygote'?" That is a different question, and are you looking for some sed-like thing?

Categories : Bash

How can i fix my functions in bash
The way you're passing and using function arguments doesn't make sense. The one I see that's blatantly wrong is the first: check_parms () { case $# in 1) ports='1-1023' host=$1 ;; 2) ports=$1 host=$2 ;; *) echo 'Usage: portscan [port|range] host' exit 1 ;; esac } #... then in the main program: check_parms $# To understand the problem, suppose the main script is

Categories : Bash

Replace multline text with indentation using sed
Given that the data is in the file data.xml, this should do the job: $ sed '/<servlet>/,/</servlet>/ { > /<init-param>/,/</init-param>/ { > /<param-name>listings</param-name>/,/<param-value>/ s/false/true/ > } > }' data.xml It is rather careful to ensure that it only changes false to true in the <param-value>

Categories : Bash

How to disown bash process substitution
I would just define a short shell function to_logger () { exec /usr/bin/logger -t "$1" } and call your code with the minimally longer 2> >(to_logger my-tag) command arg1 ... This has several benefits: The command can be any shell construct; you aren't passing the command as arguments to another command; you are just redirecting standard error of an arbitrary command. You are spaw

Categories : Bash

Are there conventions to writing a --help message?
As with much (most) stuff in UNIX, this is purely a tradition. Programmers find these kinds of --help messages useful, so they try to imitate the --help messages that they find most useful, and the tradition is born. It is a bit unfortunate for people that have their first encounter with UNIX that it usually takes some time for these traditions to be codified in some way, there is simply no compre

Categories : Bash

Expect not correctly setting Vagrant passwd
Ended up with PASSWD=$(expect -c ' log_user 0 proc abort {} { puts "Error with setting password?" exit 1 } spawn passwd vagrant expect { password: { send "vagrant " } default abort } expect { password: { send "vagrant " } default abort eof } puts "User Vagrant has had password set..." ')

Categories : Bash

pass small number into awk inside shell not working
You are missing $ in the call of if (a<b): if you want to refer to the column number a, you have to say $a. Just do: awk -v a="$column" -v b="$cutoff" '{ if ($a < b) print}' $file > $file'.'$cutoff ^ Or even shorter: awk -v a="$column" -v b="$cutoff" '$a < b' "$file" > "$file.$cutoff"

Categories : Bash

How to tell a script to stop when a execution of script that it calls ends with specific condition
Standard way is to exit with a non zero exit status on error: if (( len < 10 )) ; then echo Mask is not at least 10. >&2 exit 1 fi You can then simply check the exit code: /home/script1 && /home/script2 If there are several things that can go wrong and you want to react to a failure, you can exit with various exit codes and examine them in the parent with $?: /home

Categories : Bash

store ftp command output in a variable
One of the ways to get FTP to act automatically is to use a Netrc file. By default, FTP will use $HOME/.netrc, but you can override that via the -N parameter. The format of a netrc file is fairly straight forward. A line is either a Macrodef or a line that contains login information. Here's an example below: Netrc File mysystem login renard password swordfish another login renard password 123456

Categories : Bash

Bash Script to Print to CSV File for specified number of lines
I transformed your pseudo code into real code, corrected a few paste errrors. I am sure you are able to do the rest of the work. #!/bin/sh # $ date; date --date='now +10 Seconds' # Fri Nov 21 17:28:33 CET 2014 # Fri Nov 21 17:28:43 CET 2014 var1=$(date '+%d%m%Y') # date (format DDMMYYYY) time=$(date '+%H%M%S') # time (format HHMMSS) var2=$4 # duration (in seconds) if [ "" = "$var" ]; then v

Categories : Bash

Bash while read and saving variables
Yours is basically a variant of http://mywiki.wooledge.org/BashFAQ/024 but the whole script would benefit from a substantial refactoring which also coincidentally removes this problem. kdip=$(awk -F ':' '/Kunden-IP-Adresse/ && /4948/ { k=$2; gsub(/;/,"",k) gsub(/^[ ]+|[ ]+$/,"",k); print k; exit(0) }' test) If there are more variables you want to extract, just have the Awk scr

Categories : Bash

Script which replaces special ASCII keys with text
You can simplify the sed command as sed -i 's/xc3x8[0-5]/A/g' FILENAME To iterate through all the csv files in a directory and apply the sed for FILENAME in *.csv do sed -i 's/xc3x8[0-5]/A/g' $FILENAME done

Categories : Bash

how to make vagrant use bash and resolve `[[: not found`?
If the script only contains trivial bashisms, you can simply rewrite it to sh-compatible, and change the shebang to #!/bin/sh. Change if [[ -z $NODE_VERSION ]]; then to if [ -z "$NODE_VERSION" ]; then (The double quotes should properly be used in the Bash version too.) However, recognizing and fixing Bashisms in a large script is potentially a nontrivial endeavour. If the script is specif

Categories : Bash

increment a variable in bash ` i=0; ls>$((++i)); echo i=$i; ` why the result is i=0
The difference between echo and ls is that ls is an external command /usr/bin/ls, while echo is a shell builtin. Try replacing it with /usr/bin/echo (if it exists on your system). You'll get the same behaviour - it seems the redirection happens in a subshell that runs the command. Compare: $ i=0; /usr/bin/echo > $( ((++i)); echo inside $i>&2; echo $i ) ; echo i=$i inside 1 i=0

Categories : Bash

[Shell Script]Get httpreqest POST in shell script
What you use to send the POST is completely irrelevant. If your shell script is invoked as a regular CGI script, the POST data will be available on standard input. #!/bin/sh cat >file Perhaps you want to add unwrapping of the application/x-www-form-urlencoded container but in essence, the above is all it takes to do what you are asking. Here's the obligatory caution -- you probably don't a

Categories : Bash


Recently Add
How to test if a variable exists and has been initialized
Add stdin as another file to a tar archive
Sum of all rows of all columns - Bash
I'm having an error while "gem uninstall rails"
what should be the if condition for separating big files during copy process?
awk script to print in between result before the final result
Is it necessary to quote command substitutions during variable assignment in bash?
Spliting specific word out in sentence in BASH and AWK?
Choosing directories to output by timestamp named directories
sed remove first two characters if some string existed
what does this strange little yellow arrow below the command prompt mean?
Windows batches in Cygwin with spaces in path and arguments
Tree hiearchy in Bash
How to redirect the output of time command to a log file?
Change files format from '.less' to '.scss'
Interleave two wildcard commands
Multiple options for the same `case` result in `bash`
Bash - default size in printf
Shell Scripting: awk not printing local variables correctly
Files in docker container disappear
Argument grouping in bash scripts
Inquire in fortran 90
How to write a decimal for loop in bash
Copy and Delete
Sed and UTF-8 encoding
Removing part of a line? [bash]
How can i fix my functions in bash
Replace multline text with indentation using sed
How to disown bash process substitution
Are there conventions to writing a --help message?
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.