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

-3
votes
0answers
31 views

unix script for this [on hold]

Have two files File1 and File2, each file should have two columns. File1 should have Customer_ID and Customer_name columns with ‘|’ as delimiter. File2 should have Customer_id and Dept_name ...
0
votes
1answer
49 views

Syntax error near unexpected token `(' inside script

When I use below code in Ubuntu terminal, it works fine: rm !(*.sh) -rf But if I place the same line code in a shell script (clean.sh) and run shell script from terminal, it throws error as this ...
0
votes
2answers
18 views

wget, logging the output and the response

I calling an url using wget. This url gives me a response, its a Message id. I want to write the logs to a log file, with the message id as well. Also the log should be appended each time. I trying to ...
0
votes
1answer
18 views

Faster way to enter in command mode with vi mode in the shell

I want to use the vi mode in bash but I find the ESC key a little bit too far, as for vim. The ideal can be to keep a key pressed, like ALT or the caps lock, to stay in command mode and be in insert ...
2
votes
5answers
475 views

How to add a password to a BASH script

I want to create a script to run the following BASH command: mysqldump -u [username] -p [db_name] > [path to backup file] Which results in a backup file. When running this in BASH, it prompts ...
0
votes
4answers
88 views

Fast way to add/append to large a file [on hold]

I have a bash script that reads a rather large file, line by line, and for each line does some processing and writes the results to another file. Currently I am using echo to append to the end of the ...
0
votes
3answers
40 views

How do I create a directory for every file in a parent directory

I have parent folder and inside this folder I have 4 files ParentFolder File1.txt File2.txt File3.txt File4.txt I wanted to create subfolders inside the parent folder and ...
1
vote
2answers
39 views

Compare Dates by awk

I have the below file: 1,2,3,4,5,2015-10-13,7,8,2037-01-15 1,2,3,4,5,2015-09-05,7,8,2040-01-15 1,2,3,4,5,2015-09-15,7,8,2016-06-15 1,2,3,4,5,2015-10-13,7,8,2015-07-08 ...
0
votes
1answer
26 views

How to concatenate tables from different directories with only one header [on hold]

I have several directories ("amazon", "niger",...), in which I have several subdirectories ("gfdl", "hadgem",...), in which I also have several sub-directories ("rcp8p5", "rcp4p5",...). In this last ...
0
votes
1answer
37 views

Redirect console output in sed in background process don't give back hand

I'm using sed to add the date at the beginning of every lines given by a command (which use vlc and never stops...). I found this way on another stackexchange post and that works as expected. command ...
0
votes
1answer
24 views

Problem with loading settings from .bashrc

I have got strange problem with terminal settings. I am Debian 3.16.7 user. I saw .bashrc file using ls -a but I couldn't open it (no file comunicate), so I restored it from /etc/skel/.bashrc. Now ...
1
vote
2answers
38 views

How to forcibly update a file if left unchanged after 55 minutes? [on hold]

I need a log file to be updated if it has been left unchanged during 55 minutes. For example, say it is now 19:00 and IOstatDisk2.log hasn't changed since 18:00: solaris1a:/var/tmp ROOT # ls -ltr ...
10
votes
2answers
264 views

Resource usage using pipe and here string

We can get the same result using the following two in bash, echo 'foo' | cat and cat <<< 'foo' My question is what are the difference between these two as far as the resources used are ...
0
votes
2answers
52 views

How to use cp command in bash script to copy files with spaces ans $ characters in it? [duplicate]

I am trying to copy some files with spaces and $, @ symbols in their file names in a bash script but the script fails to copy the files stating it cannot find the file. I can see that it is treating ...
0
votes
1answer
26 views

Folder organization

I have several folders ("amazon", "niger", "rhine",...). Inside each of them I have several subfolders ("gfdl", "hadgem", "ipsl",...). Each subfolders is composed by 5 subfolders (e.g. in "amazon", ...
-2
votes
1answer
51 views

Bash Code Injection Vulnerability On Linux

Found a new bug in Linux System, a bash code injection vulnerability. The solution to this is the update the bash package. yum update bash My Question is "do I need to reboot the system"? ...
3
votes
2answers
78 views

Using bash variables in perl command in bash script

I am trying to generate a hashed password as in /etc/shadow file, using bash script. The user is prompted for the password which is saved in a variable PSWD. I have extracted the Hash and the salt ...
1
vote
0answers
27 views

Recording shell output for interactive commands

While looking into a shell redirection problem, I found a couple of answers that pointed me to the script command. As I understand it, script just records in- and output of the terminal, and allows me ...
1
vote
3answers
38 views

Set, backup and restore colors in the terminal

I use this program to display all color available in the terminal. That waht I get: This program doesn't show me colors below 100. Why? Is there a way to display them. Is the are way to change ...
0
votes
1answer
37 views

error ./c.sh: line 24: [: too many arguments in shell program

I am trying to make a shell script to print the amount of time user was logged into the system but I encountered a too many arguments error. I tried many methods from the internet but none worked. ...
1
vote
1answer
64 views

Issue with ':' character in Bash script over SSH

I am currently writing a script that will perform backups on a set of databases, comress them, encrypt them, transfer them to a separate storage machine, and verify that the file made it successfully. ...
1
vote
2answers
60 views

What Bash Statement does

Can you explain to me what the below statement does. grep `date +%Y-%m-%d --date='1 day ago'` /path/to/file/FILE_PREFIX_\`date +%Y%m%d --date='1 day ago'`.dsv | grep -v 'ERROR' | cut -d "|" -f 2 | ...
3
votes
3answers
135 views

If statement string comparison

I'm reading a csv file with 14 values per line. I want to convert the HEX value from 10th [f10] value to a DEC value. In order to do this if the 7th [f7] value must hold EnHr or EnSt or SpJb or Chem ...
1
vote
4answers
55 views

One column into two

I have a file that is one column, and I need to split it into two. Have tried column command and doesn't seem to work: 123-zyx 234-yxw 345-xwv 456-wvu 567-vut 678-uts
3
votes
2answers
71 views

Why does man page completion fail after su?

I have a default Debian 8.1 installation. I do su man apt<TAB> but get nothing. I do see the manual when I write man apt-get in both modes: as user mas and as root. However, tab ...
0
votes
1answer
30 views

Reload network interfaces without rebooting

I'm doing a BASH script for Arch Linux in a Raspberry Pi 2. The thing is that in some point I'd like to reload the network interfaces without reboot and have my new named network interfaces (en0 and ...
1
vote
2answers
42 views

Best way to make variables local in a source'd bash script?

I have a bash script that generates a report on the progress of some long-running jobs on the machine. Basically, this parent script loops through a list of child scripts (calling them all with ...
2
votes
5answers
70 views

bash expanding to same value instead of line by line value in sed command

I have a file containing numbers in it say numbers.txt as follows. 9374541632553 51243747879841 32030098896914 84654557358238 11000656847765 I want to convert it to the following format. ...
1
vote
4answers
70 views

How to number a string in each line of a file

Given file.txt that looks like this: line_ some text line_ some text line_ some text How can I number the lines like this with Bash: line_1 some text line_2 some text line_3 some text Here is my ...
1
vote
2answers
14 views

How to pass an argument from a bash script to 'x-terminal-emulator -e bash -c'?

Let's say I've got this script : x-terminal-emulator -e bash -c 'echo hello > ~/text' I call it foo.sh and make it executable. If I execute this script I'll have a text file in my home folder ...
1
vote
2answers
59 views

What's the most efficient way to log crontab shell script errors with error occurred time?

A common way to log crontab task errors looks like below: 1 */8 * * * sh /pseudo_path/test.sh 2>> my_err_log It's a concise command, but it can't record the error occurred time, and the path ...
0
votes
2answers
38 views

Variable expansion inside parenthesis and quotes

In the script below, I can't seem to make $var1 expand in the second statement. I've tried $var1, ${var1}, echo $var1 and '$var1'. It is inside a few sets of quotes and parenthesis which I guess is ...
3
votes
1answer
22 views

Bash script with conf file with unknown number of sets of variables

I am writing a bash script that has a configuration file. The configuration file will have sets of mode and mtu values. There can be zero or as many sets as the user defines. The bash script will ...
1
vote
2answers
45 views

Grep and ignoring leading whitespace

I've been working on a bash script to search for names of defines, and then grab the hex values for them and put them in the list. Once I have the list of names I'll attempt to search for "#define ...
0
votes
1answer
30 views

Sending special characters and new lines via KANNEL

Howto send message to kannel with lines and special character. Example if I have file message.txt which have following text line1 with few special characters like @ " / : line 2 spaces words etc line ...
0
votes
0answers
32 views

Drawing a histogram from a bash command output

I have the following output from a miRNA Predictor: Read Sequence:hsa-miR-576-3p MIMAT0004796 (22 nt) Read Sequence:gi|182396|gb|M74088.1|HUMFAPAPC Human APC gene mRNA, complete cds (8972 nt) ...
1
vote
1answer
19 views

Arrange program windows out of bash script?

I'm writing a shell script to automatically launch my work environment. It would be pretty nice to arrange the program windows automatically (for example vim opens at the left on desktop, and browser ...
1
vote
3answers
35 views

bc scale: How to avoid rounding? (Calculate small binomial probability)

Following code calculates the Binomial Probability of a success event k out of n trials: n=144 prob=$(echo "0.0139" | bc) echo -e "Enter no.:" read passedno k=$passedno nCk2() { num=1 ...
0
votes
0answers
31 views

How to scan for wireless networks fast

I have written a script which scans for wifi networks with iw dev wlan0 scan and put the SSIDs in a file. Is there a similar tool wich works a bit faster?
0
votes
1answer
30 views

How to copy files to the timestamp generated directory?

Hello I am trying to copy all files from Documents directory to the backup directory that has a timestamp. So I have created a directory called bk$( the time stamp of the directory) and I am trying to ...
1
vote
0answers
28 views

Calculate Out data Kb/s for specific PID

I have this command cat /proc/8221/net/netstat | grep 'IpExt: ' | tail -n 1 | awk '{ print $9 }' This shows me out bytes in that moment right? If yes, how can i show total kb/s in just one command ...
2
votes
2answers
58 views

Bash script function that changes the value of a variable

I'd like to make a function for a BASH script that changes the value of one of its arguments, that is a variable. The function that I did is: chck_rgx () { # Checks that the given name for a ...
2
votes
2answers
19 views

Is there a way to colorize output per stream from a program [duplicate]

I'm looking for a method to have bash colorize the output from a command based on what stream it was written to the terminal from. Is there any way to get it to colorize per stream? Like for example ...
1
vote
1answer
32 views

Get value of environment variable in for loop

I have several environment variable pam_branch app_branch worker_branch I use an array to define different projects and I want to get the values of these env var by rebuilding them in a for loop ...
2
votes
1answer
26 views

Dynamic Variable in KornShell Script

This KornShell Script (ksh): envir=Dev eval "${envir}foo=bar" echo "$Devfoo" Output: bar But I will not know what value is assigned to envir variable. So I want to do something like this where ...
0
votes
1answer
39 views

Bash : rewriting a file which is read in same line

I'm working on a bash script for partially automating router connection in command line. I'm a newbie in Bash. This is part where I have a problem: #!/bin/bash STRING2="ESSID" MYPWD=$(pwd) sudo ...
0
votes
1answer
22 views

Extract source commands of an existing gnome terminal session? [duplicate]

I have a bit of a situation. One of my co-workers just overwrote everyone's bashrc and bash_profile files. My custom settings have been lost. However, I still have a terminal open which sourced my own ...
2
votes
3answers
176 views

copy from file and paste in the terminal without x server

I have got an ubuntu linux without x server installed on it (cos it's only a gateway). I am requested by an application (ossec,-my question is not ossec related-) to paste information into the ...
3
votes
1answer
308 views

Add 30 days in date

Using bash or mysql , how can I add 30 days in user expiry table? Example I have DB name USERS and table expiry like this: USERNAME EXPIRATION JOHN 2015-09-26 I want the command to take ...
2
votes
2answers
286 views

How to copy and add prefix to file names in one step?

I want to copy and rename multiple c source files in a directory. I can copy like this: $ cp *.c $OTHERDIR But I want to give a prefix to all the file names: file.c --> old#file.c How can I ...