Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead.

learn more… | top users | synonyms

0
votes
0answers
34 views

sed using a bash variable [duplicate]

I am attempting to identify 2 lines a in a file, that match a pattern (path) $ dir_target="./CUSTOM/Database/XXRBS/DML/Insert" $ cat csv.out ...
3
votes
1answer
188 views

Problem with public key on apt-get update

I have Lubuntu 16.04. My problem is similar to this questiuon: sudo apt-get update Get:1 http://it.archive.ubuntu.com/ubuntu xenial InRelease [247 kB] Hit:2 ...
2
votes
2answers
37 views

bash prompt got reset every time I login

I asked this question some time ago about the shell does not displaying the path. Recently I found out that the .bashrc does not get sourced (and this should be a normal practice?). Currently, the ...
2
votes
2answers
27 views

Adding a user to a group

I have a user and a group called awe on my server. It's home directory is /home/awe I created a new user called c37. I then ran the following command (as root) usermod -a -G awe c37 Now when I'm ...
0
votes
2answers
37 views

Renaming multiple files using sed

I have following set of files top_axi_256_wrapper_05.02.01.14.00_sample06.tgz top_axi_128_wrapper_05.02.01.14.00_sample06.tgz I want to replace 05.02.01.14.00 part with 05_02_01_14_00. So the ...
2
votes
2answers
43 views

How can I more efficiently collect data from users on a vm?

I'm teaching a course this summer. My students' first assignment will be to install a virtual machine that I created (the machine will run Ubuntu). Upon installation they are to run the following ...
1
vote
1answer
32 views

extract time range from log file using AWK

I am trying to extract time range from a logfile by passing shell variables in awk. This is how my log file is. 2014-11-24 12:58:59.290 1.1.1.1 etc.. 2014-11-24 13:58:59.290 2.2.2.2 etc.. ...
1
vote
1answer
41 views

How to organize files in main directory into smaller amount of files in sub-directories [duplicate]

I have a directory of 150 files that I wanted split into sub-directories of 25 files each: 1-25 into dir1, 26-50 into dir2, and so on. How can I accomplish this? dir1/fre_4_g2_c3654214.h3 ...
2
votes
1answer
31 views

How can I put this string manipulation in a loop so it continues until there's nothing left to do?

I am creating a script to strip off all parts of a url other than "domain.com". I've managed to get most off, but I'm running into a problem with subfolders. Here is my code: domain=$1 ...
10
votes
1answer
145 views

Why do these bash fork bombs work differently and what is the significance of & in it?

I get how a normal fork bomb works, but I don't really understand why the & at the end of the common bash fork bomb is required and why these scripts behave differently: :(){ (:) | (:) }; : and ...
11
votes
1answer
522 views

Is there any way to tell if a shell script was killed with signal 9

I have a bash script (called from a java program) that keeps getting killed. I always catch the signal 15 with trap but then some other signal comes along that I suspect is signal 9 but am in ...
0
votes
0answers
16 views

How do I submit a header with curl? [closed]

If I want to submit a header with curl (The header being “Authorization: Bearer token”), how do I do that? I wrote this script for bash curl -i \ -H "Authorization: Bearer fefef" \ -X POST --data ...
1
vote
3answers
46 views

How can I use string manipulation to detect and remove two different parts of a string?

I'm making a script that will remove the http:// or https:// from a URL. So far I've got it to remove the http://, but I can't seem to figure out how to modify it so that it will remove either that ...
-1
votes
0answers
26 views

ngrep output redirection with -q option

when using ngrep in bash with -q option the '####' characters are gone and only the matches are shown but redirecting this to a text file results only in a empty file. sudo ngrep -q >> log.txt ...
0
votes
2answers
45 views

Cron Job: Redirecting shell script output to a file

Just an one line shell script below not working as a cron job but executing directly from terminal works fine: #!/bin/bash echo "Executed" >> ./crond.log 2>&1 What might be the ...
2
votes
1answer
28 views

How to get a list to be entered in quotes

firstly I am a total n00b with scripting, so please forgive any incorrect terminology. I have a simple script that runs a python script (used to deduplicate emails via IMAP) after a user has entered ...
2
votes
2answers
39 views

What does the < (left chevron / triangle bracket) do? [duplicate]

I am having a difficult time wrapping my head around this. I understand that the > (right chevron) is for redirecting the STDOUT of a program to a file, as in echo 'polo' > marco.txt will ...
0
votes
0answers
23 views

grep, failing to find an existing file with correct path given and checked [duplicate]

I need help with grep. Below is what I've written and the If function is working, but the grep part is saying grep: ~/tmp/file.txt: No such file or directory however if I copy and paste the pathway on ...
-4
votes
0answers
14 views

how should i update values in bash (ATM MACHINE) [closed]

AOA Guys I am working on my semester project and i am making ATM machine.Problem i am having is to ** update values of user account at run time ** need help on this ie. i want to change balance of ...
0
votes
3answers
43 views

How can I subtract two variables in bash?

Hi Guys am getting error please help to sort out. I am new to scripting Script: #!/bin/bash value='55' size=`df -kh | grep '/vol/cdr/MCA' | awk '{print $5}'| sed 's/%//g'` if [ "$size" -gt "$value" ...
4
votes
2answers
29 views

Question about behavior of control key shortcuts

I am confused about how Ctrl-key combinations work in terminal. In bash man page, there are various combinations such as: C-e - go to end of the line C-f - go one character forward etc. But then ...
1
vote
1answer
38 views

How to follow the activity of one specific file [closed]

I have currently MAAS deployed on one of the servers. It all works (most of the time). Now I have added some lines in the WOL file for MAAS (/etc/maas/templates/power/ether_wake.template). I wanted to ...
1
vote
1answer
31 views

How can I edit my bash script to account for whitespace entries? [duplicate]

I made a script to automate ffmpeg conversion from mkv > m4v > open the m4v in Subler.app to import the metadata manually, at which point I'll move the file into my iTunes library. I use iTunes ...
1
vote
2answers
68 views

BASH: count # of words in each line of a document

I need to identify patterns in a text file for further analysis. So the input files may contain semi-structured text as follows; file1 905:john: abc123: john@doe.com: US 920:eric: ericaA: ...
3
votes
1answer
38 views

Bash: Why is read returning a nonzero exit status while reading my file?

I'm trying to read two files line-by-line in Bash and do something to each of their lines. Here is my Bash script: #!/usr/bin/env bash die() { echo "$@" >&2 exit 1 } extract_char() { ...
1
vote
1answer
31 views

Exporting a Shell Variable From the Command Line

I'm playing around with duplicity via a script that looks like this: export PASSPHRASE=SomeLongGeneratedHardToCrackKey duplicity /etc scp://FtpUserID@ftp.domain.com/etc unset PASSPHRASE Here's a ...
-2
votes
2answers
35 views

check if ip is available [duplicate]

Is it possible to check if ip is free with a script pseudo code would look something like this if [ip is available] echo "IP is available" else echo "IP is not available" fi Can ping be used ...
0
votes
0answers
35 views

escaped strings inside variable returned in single quotes

I have a number of mp3 files without correct file names. What I wish to do is to create a script that will read the artist and title from mp3 tag and rename the file according to the tag. The script ...
0
votes
1answer
40 views

why looping over string is different when it's in a variable

I am wondering why when you iterate over a variable n="1 2 3" you get this: $ n="1 2 3"; for a in $n; do echo $a $a $a; done 1 1 1 2 2 2 3 3 3 but if you don't put the string in a variable first ...
0
votes
0answers
12 views

Any good way to momentarily block submitting a command if a tab-completion is ambiguous?

Occasionally I go to type a command, think I've gotten enough of the filename that Bash can complete it, hit Tab, and then hit Enter before I notice that the filename didn't complete. Most of the time ...
2
votes
1answer
37 views

Highlight nth column of ps output

I'm trying to find the best way to highlight a specific column of some output. Specifically, I'm trying to highlight the 9th column (which is %cpu of the command: ps -eo ...
1
vote
0answers
40 views

What are newline rules in Bash? [closed]

I have very long commands, I want to beautify the reading of the commands using linebreaks. What are some good line-break using \ rules in Bash? I know, I should never follow the \ with a space. ...
4
votes
1answer
34 views

bash 4.3 “multiple dot” commands fails silently

I just noted this on bash 4.3; exact version number is 4.3.42(1)-release (x86-redhat-linux-gnu). $ .. $ ... $ .... $ ..... Why do the "command not found" is not prompted ? $ ... $ echo $? $ 127 ...
2
votes
1answer
29 views

pdflatex/lualatex called from shutdown script can not find installed packages

At work I have set up a little backup script on my Ubuntu 14.04.1 machine. The script backs up my machine to an external hard drive. After this is done it copies a LaTeX project to my Dropbox and ...
2
votes
2answers
89 views

Using tar with find

Lets say we want to find a certain files , use tar on them and delete them. I tried using touch "mycompress.bz2.tar" find . \( -name "*.c" -o -name "*.sh*" \) -exec tar ujf "mycompress.bz2.tar" {} ...
4
votes
1answer
72 views

Executing commands in an elevated bash process by writing to the standard input of its parent script process

I have a simple bash script bash.sh that starts another bash instance using pkexec. #!/bin/bash bash -c 'pkexec bash' When executed this shows a prompt for the user to enter their password. The ...
3
votes
1answer
86 views

Multiple variable assignment from different parts of one command pipeline

Say I have 2 variables that I am assigning as follows: psaux=`ps aux | grep someProcessName` pscount=`ps aux | grep someProcessName | wc -l` I would like to combine the assignments in one line, so ...
0
votes
2answers
37 views

Awk: Print last N columns, where N is passed through a variable

My input variable $dirPath contains directory path. The action is to be able to retrieve the last N values in the directory path, where N is passed through a variable $depth. For a fixed N value (say ...
2
votes
2answers
60 views

Why won't this bash command run when called by python?

The command $ find ~/foo/ -type f -iname "*.txt" -print0 | parallel -0 cat uses GNU Parallel to print all the .txt files under ~/foo/. I have a python script where I want to call this bash ...
0
votes
1answer
55 views

Prepare update command using sed

I have a output file that contains 3 different column data- ['AARF'],SAMPLE12,2016-01-05 12:00:00-0500 ,529OFFST,2015-04-16 08:04:21-0400 "['EPROSP_IWS', ...
0
votes
2answers
54 views

For loop runs twice,

So I am fairly new to bash scripting, but I want a bash job that will: Create a post-dated timestamp. (either as a var, or to a file) Read lines from a file named feeds.txt. Separate the number ...
1
vote
2answers
28 views

Repeating current loop iteration if some condition is met (bash)

I'm writing a bash script which takes files and directories as arguments. It will loop through its arguments and rename the current argument if some condition is met. When this happens I want also to ...
2
votes
3answers
35 views

echo all *.tex filenames in a specific directory

I have a directory structure like this: ├── lebenslauf │   ├── lebenslauf.out │   └── lebenslauf.tex ├── thirdPage │   ├── auto │   │   ├── test.el │   │   └── thirdPage.el │   ├── missfont.log │   ...
0
votes
1answer
60 views

Match words in array line by line to a seperate file

Here is a sample of my input data: $9.99,Titan the Power,www.example.com,565654 $15.99,Conan The Barbarian,www.sure.com,565438 $1.99,Julia Cesar,www.bfg.com,69722 I have written this code so ...
0
votes
2answers
56 views

How to determine what IP addresses are available in a hosts table?

I'm working on a script that will read from the /etc/hosts file and determine what IPs are available in the hosts file. The way the hosts file will look is as followed: 172.17.164.2 System1 ...
0
votes
3answers
63 views

Defining bash function dynamically using eval

I'm trying to define a bash function dynamically using following code: delegate_function() { echo "output from delegate"; } eval "parent_function() { echo $(delegate_function); }" The intent is to ...
0
votes
1answer
33 views

sed replace with value from an argument [duplicate]

Although this seems like a simple task, the sed call is not substituting the value that I send for IP. Instead, it is replacing localhost with "${IP}". substitute() { export IP=$1 echo $IP ...
1
vote
2answers
37 views

Scope of Local Variables in Shell Functions

After reading 24.2. Local Variables, I thought that declaring a variable var with the keyword local meant that var's value was only accessible within the block of code delimited by the curly braces of ...
0
votes
0answers
48 views

How can I find where tmux is installed on my computer? I would like it to autostart when bash starts

I know that this exists. But it isn't working, and when I try to find tmux in the "bin" directories of my computer, it doesn't find it. How is it working when I enter tmux into terminal then? ...
1
vote
0answers
36 views

compare variable value with part of IP [duplicate]

I have several IP addresses that I want to list it based on internal or external IP: our internal IP for example start with 10.10.10.X, I was thinking about writing bash script to do this job for me, ...