Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

0
votes
2answers
30 views

How to scrape multiple IP's and add in a script as a variable?

I am trying to add in my script an awk statement or a: if; else; then if eth0:4 is a match then put in eth0:4 IP How would you get the IP in your script as a variable if you have multiple IP's ...
3
votes
3answers
13k views

Pass command line arguments to bash script

I am new to bash script programming. I want to implement a bash script 'deploymLog', which accepts as input one string argument(name). [root@localhost Desktop]# ./deploymLog.sh name here I want to ...
0
votes
0answers
69 views

shell script prompting for password but not taking it while doing tar

In my shell script, I have following lines: function tarIt() { FILE_OWNER=$1 TAR_FILE_NAME=$2 FILE_NAME=$3 su - $FILE_OWNER -c "tar -czf $TAR_FILE_NAME $FILE_NAME 2>&1" if [ ${?} ...
0
votes
0answers
23 views

Is there a way to add a timestamp to the logs for qsub job?

I'm submitting jobs on a cluster via qsub but the error/output logs don't have a timestamp, making debugging more difficult. Is there a way to add timestamps to the logs in the bash script? Appreciate ...
2
votes
4answers
98 views

How to make diff command ignore certain lines of second file(bash)?

For example: file1.txt: I need to buy apples. I need to run the laundry. I need to wash the dog. I need to get the car detailed. file2.txt I need to buy apples. I need to run the laundry. I need ...
0
votes
3answers
45 views

copy the contents of a variable in a text file

I know this is a stupid question but I want to know how I can put the contents of a variable in a text file. This variable is a string that I want the code with the base64 command.But this command ...
0
votes
0answers
21 views

Linux, dev/tcp validation and kill the process with timeout

I have this part of code, I need to validate if the connection was ok or not, AND, if the process is running more than 3 seconds, it will be killed. But, I dont know how to keep the value of the ...
2
votes
2answers
421 views

How to permanently enable scl CentOS 6.4?

I installed a newer version of devtoolset (1.1) and was wondering how I would go about permanently setting these to be default. Right now, when I ssh into my server running CentOS, I have to run this ...
0
votes
1answer
46 views

How to accumulate data for the previous x number of days

Q: For the argument of the question, say today is 26/03/15. How can I 'accumulate' data for the last 5 days. But these dates are just an example. Ideally I would like to be able to accumulate data ...
0
votes
0answers
13 views

I have used --data-urlencode with continue command character “\” to continue command on next line but can't get output.

curl -k -u user:password -d "output_mode=csv" --data-urlencode search='search source=*/**/94.0*M2E-CSI* \ "Caused by" \ | table host, source' -d 'max_count=1' -d 'earliest_time=-32h' -d ...
1
vote
2answers
24 views

stdout to log, stderr to log and console

I'm trying to send all output to a log, with stderr also displaying in the console. ..with the log entries in order and some method to send comments to the log+console (same as stderr). exec ...
4
votes
1answer
46 views

How can I launch a command, wait 2 seconds and return the output without killing the command?

I'm trying to launch a command from php with shell_exec which calls a bash script that launches a program that stays running, but sometimes this program throws an error and exit, what I need is a way ...
3
votes
3answers
446 views

Including sub-parameters in help options to execute wisely without getopt or getopts?

I am writing a script which can choose a file and print specific content. For example, san#./script.sh Expected Usage : ./script.sh --file1 --dns (Here it checks for file1, search for dns name and ...
0
votes
1answer
27 views

Using egrep in Bash

I'm taking a UNIX course atm, and I've got a newb question. In the following code, I'm getting an error and I'm not sure why: [name@unix ~]$cat test123 123 456 789 1011 1213 [name@unix ~]$egrep ...
1
vote
1answer
36 views

Displaying “No Results” When AWK Command has no output

I have the following code, thank-you to the people who helped me here awk -F: '{if(system( "[ -d " $6 " ]") == 1) {print "The directory " $6 " does not exist for user " $1 }}' /etc/passwd However, ...
1
vote
4answers
3k views

“Can't cd to /home/user” when sourcing a script

I have this script: echo $HOME cd $HOME cd / cd /usr/local/src/ When I run it like this . script.sh I get this output: /home/user : No such file or directory : No such file or directory : No ...
2
votes
0answers
59 views

Bash regular expression comparison fail for hex byte \x01

Bash regular expression fails to compare correctly for $'\x01' when End-Of-String char $ is used. All other byte values (seem to) compare correctly. Using GNU bash 4.1.5(1). Is this a bug, or is ...
3
votes
2answers
61 views

Why can't I load modules while executing my bash script, but only when sourcing it?

I am using modules to control the packages on my system and I have python/2.7.2 installed as a module. I have simple python executable python_exe.py which I am going to call from a simple 'driving' ...
3
votes
4answers
102 views

Delete folders which not match a list

I need practical example how get rid folders which are not in the list in Linux. So i do not need to compare its contents or md5sums, just compare folders names. For example, one folder has few ...
0
votes
2answers
30 views

recording total runtime in bash script

I have the following script. When it runs it prints the Start and end Times to the file 'result.txt'. However, I also want to record the total runtime (end-start), but where I am doing echo runtine ...
-1
votes
2answers
38 views

Linux Bash Scripting Issue with Wildcard

I'm having issues with what I imagine should be a simple bash command I'm basically just trying to loop through a bunch of files and get there names `ls ./*.sql` # list all files ...
1
vote
1answer
39 views

Figuring out the dates for a given week

With date -d @[some_timestamp] +"%U" the end result is a number between 0-53, which represents the week in which the [some_timestamp] is located. So if I have an arbitrary timestamp ie 1426815663, the ...
14
votes
6answers
70k views

Why does find -mtime +1 only return files older than 2 days?

I'm struggling to wrap my mind around why the find interprets file modification times the way it does. Specifically, I don't understand why the -mtime +1 doesn't show files less than 48 hours old. ...
0
votes
0answers
23 views

KSH/BASH Comparsion b/w Two Array and then logical OR operation at other function (GNU bash 4.2 version)

I am new to unix and learning it basics. I wanted to compare same index of two different arrays and on the basis of comparision I wanted to put a data to other array. First I tried to use it ...
2
votes
4answers
195 views

How to 'drop' characters from in front of a string?

I have a string that I would like to manipulate. The string is H08W2345678 how would I be able to manipulate it so the output is just W2345678? Similarly if the I wanted to drop the last 4 ...
1
vote
2answers
56 views

Redirecting stdout and stderr of specific lines

I am reading a file and redirecting the entire output to a file. I would like to redirect stdout and stderr of certain expressions to screen as shown below (just an example): #!/bin/bash OLDIFS=$IFS ...
1
vote
1answer
37 views

read input from user in while loop having input and output redirection

This is my code: while IFS=',' read a b c; do read input echo $input done 3<&0 < input.csv > output.txt I took care of input redirection by redirecting through pipeline. But ...
1
vote
3answers
66 views

UNIX KSH/BASH Call by Reference using Array (at GNU bash 4.2)

I am new to Unix shell scripting My code is as follows: i=0 for var in 'a' 'b' 'c' 'd' 'e' do content[i]=var ((i=`expr i+1`)) done a=10 b=50 c=40 d=90 e=100 Now I wanted to print the local ...
7
votes
2answers
940 views

Is it possible to strace the builtin commands to Bash?

Inspired by this question, titled: When are the built-in commands loaded to memory, while attempting to answer this I tried the following command and was a bit surprised that I couldn't run it: $ ...
0
votes
2answers
51 views

How to run multiple AND in grep command [duplicate]

I'm trying to run multiple AND combination in grep command, I was able to run using two patterns: grep -E 'pattern1.*pattern2' filename Is it possible to use three or four patterns using the above ...
1
vote
2answers
85 views

Finding files that contain multiple strings

I am trying to find scripts that contain common malicious code, I need to match multiple strings within each file. What I am using is working but am not sure why I get the following in the output: # ...
-2
votes
1answer
16k views

“not a valid identifier” when I do “export $PATH”

When I run export $PATH in bash, I get the error not a valid identifier. Why?
1
vote
1answer
45 views

create an array

I want to learn about arrays and how to assign values to them, so I found this tutorial While running the following script: #!/bin/bash $names=([0]="Bob" [1]="Peter" [20]="$USER" [21]="Big Bad ...
0
votes
2answers
37 views

Run script on non-full bash-login invoked as “sh”

Good day I'm currently trying to modify my terminal to have the prompt displayed in a different colour than the whole rest of the shell, and I would like to make it white for normal users and red for ...
0
votes
0answers
34 views

reading dates from process substitution using awk. Issue with field separator, splitting tokens incorrectly

I have the following code, thanks to @Janis for the help with the process substitution. Also, apologies for creating a new question, I haven't received any recent replies on the thread of my previous ...
1
vote
1answer
48 views

Output different lines when comparing two files

I have two text files with the same number of newline terminated strings. The lines in the two files correspond to each other. The lines in each file individually might be repeated. I would like to ...
-1
votes
0answers
15 views

Script to convert CBR to CBZ with optimization?

I have a large collection (tens of gigabytes) of CBR files that I would like to convert to CBZ and as I am a space miser I want to optimize the image files as much as possible. I have the beginnings ...
6
votes
4answers
751 views

Bash prompt that won't clobber long commands

I'm trying to set up a bash prompt for - hostname(screen#):directory$ which is coloured green if the last command completed successfully, red if not. This is what I have so far, which actually does ...
0
votes
0answers
31 views

Swap OS X Command/Control keys without changing bash shortcuts

I originally asked this on Ask Different, but I think since my issue is probably more with bash this would be a more appropriate site. First of all, I know that you can use the System Preferences to ...
0
votes
2answers
48 views

Check whether text contains non-ASCII characters in a shell script

I have a file, I want to determine if it contains only English ASCII characters. I thought this is a very common question, but when I googled it, there is no direct answer or related. According to ...
2
votes
1answer
45 views

Install an additional completion function for bash

I have never used bash completion of todo.txt cli; however, I have decided to give it try. On the author's github, it says: (Optional, since v 2.9:) Install the Bash completion, either system-wide, ...
1
vote
4answers
272 views

Add/delete workstation ip to /etc/sysconfig/iptables and then run service iptables reload

I need a script to add a users workstation ip to /etc/sysconfig/iptables and then run a service iptables reload. I need the same type of script for removing this rule from iptables. I found the ...
24
votes
7answers
40k views

How can I get the size of a file in a bash script?

How can I get the size of a file in a bash script? How do I assign this to a bash variable so I can use it later?
15
votes
2answers
9k views

bash multi line command with comments after the continuation character

Consider echo \ # this is a comment foo This gives: $ sh foo.sh # this is a comment foo.sh: line 2: foo: command not found After some searching on the web, I found a solution by DigitalRoss on ...
-1
votes
1answer
48 views

Accessing array elements within process substitution bash

I've got a text file which looks like this: b4238ca2-cb8d-11e4-8731-1681e6b88ec1,https,username,password,ipaddress b4238f0e-cb8d-11e4-8731-1681e6b88ec1,https,username,password,ipaddress ...
17
votes
2answers
2k views

How did this '&' at the end of my command, make the script SO fast?

While solving some CTF challenges online, I came across a situation where I needed to bruteforce a server. This is the code I wrote: #!/bin/bash for i in {0..9}{0..9}{0..9}{0..9} do echo ...
0
votes
1answer
30 views

Printing conclusion at the end of script

In this example code I have numbers in the file "list.txt" I wanted to create folders in a specific location "target" for every number in the file "list.txt". In order to do so I used for loop as the ...
2
votes
1answer
49 views

Why does 'read' strip out whitespace even with the -N flag?

According to the manual for read (and since it is a builtin, not man read, but help read): -N nchars Return only after reading exactly NCHARS characters, unless EOF is encountered or read times ...
-1
votes
1answer
34 views

Some commands not working in bash script

I'm using Ubuntu 14.04.02 32bit. On doing some shell programming, I found out that running the script through the sh command sometimes cause errors. Is it because the sh command is invoking the ...
1
vote
1answer
45 views

Unable to track error

I am new to Unix shell scripting, While running my program I found the following errors today.ksh[36]: test: 0403-004 Specify a parameter with this command. sed: 0602-419 Cannot find or open file ...