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

3
votes
2answers
35 views

bash: loop through two string variables to create symbolic links

I have managed to create two bash variables, both of which are lines of strings. $oldfilenames which looks like path/old-filename-1.txt path/old-filename-2.txt path/old-filename-3.txt path/old-...
2
votes
3answers
67 views

Why is my elif being treated as an else statement in my bash script?

I'm building a bash script that uses wget to GET information from a server using a REST api. I'm using getopts to parse options given to the script and then using an if statement to redirect the ...
3
votes
3answers
90 views

How to do a loop to process two input files

I am using awk to do match two files and then multiply the elements of file2 and file1. awk 'NR == FNR{a[$1]=$2; b[$1]=$3; next} /:/ || !NF{print; next} {print $1, $2*a[$1], $2*b[$1]}' ...
1
vote
3answers
153 views

Use regex to check if particular directory has folders starting with specific word

I am writing a script that checks a certain directory for any sub-directories starting with a specific word. Here is my script thus far: #!/bin/bash function checkDirectory() { themeDirectory="/...
0
votes
2answers
149 views

What is the best practice between using ${var} or $var? [duplicate]

I know that ${var} and $var does the same thing. I also know that you can use brace for advanced options like ${var:=word} or ${var#pattern}. It's also explained here. But I see in some bash scripts ...
1
vote
0answers
29 views

Pipe long running process to clipboard on mac

I have a seemingly long running process (the lg cli debugger) and when I run it it prints out a uri to access the spawned debugger. I'd like to pipe this to my clipboard (pbcopy on mac) so I don't ...
0
votes
1answer
41 views

List files before a specific date in bash [closed]

How to list files before a specific date in bash?
2
votes
1answer
30 views

Cannot stop bash to expand star (wildcard character) passed to app from shellscript

I have a shell bash script wich should pass the star ["*"] wildcard character to an application without using quotation marks. I am reading since hours and always find to use "set -f" inside the ...
0
votes
1answer
38 views

Using a username starting “##” at a bash prompt

Some clown made me a sftp username that started with ##. Now I don't know if the command is wrong or the ftp server isn't responding for certain. Could someone please confirm for me that this should ...
4
votes
1answer
99 views

How can I test if a particular alias is defined?

I have a bash script that needs to behave differently if a particular alias is defined. Is there a way to test if a particular command is an alias in bash?
1
vote
1answer
47 views

How would I make this script more efficient? [closed]

I am writing a script that will systematically install Numix theme using gnome-tweak-tool. I want to make sure that I don't reinstall items if they are already installed, so I used which [name of ...
3
votes
1answer
27 views

removing duplicates from pushd/popd paths

Context linux bash pushd/popd/dirs Problem The problem scenario is very similar to the one stated in this question: removing or clearing stack of popd/pushd paths ... however the goal is not to ...
1
vote
1answer
30 views

How to stop bash being too smart restricting completion options?

I often come across bash getting in my way when I'm doing something like this: cmake -DCMAKE_INSTALL_PREFIX=/usr/<TAB><TAB> Apparently, bash doesn't see that cmake can accept paths and ...
1
vote
2answers
69 views

Rename all spaces in image file names inside html php files

Inside different htm.gz, html.gz and php.gz web files I have images and the ones in .jpg format have name with space instead of "-", but in /images/ directory where all images are located they have "-"...
1
vote
2answers
29 views

Silent stat to check file existence

I'm running a command if a file is present in one line of bash. Here is what I'm doing for now: $ stat /last_dump.sql && mysql -D my_database < last_dump.sql Is it the right way to do ? ...
2
votes
1answer
40 views

Using /dev/tcp with proxy

Is it possible to use /dev/tcp with a proxy? I only found wget is possible to use with proxy, but wget doesn't help me in my case.
0
votes
1answer
61 views

Outputting date from an array with bash

I'm trying to put together a script that will detect when someone joins my network via DHCP and then will email me the details. The problem I'm having is with parsing the epoch time in the loop. I've ...
1
vote
1answer
37 views

Using Grep In For Loop

File1 contains: 421 RP-001 421 RP-002 421 RP-003 550 SC-001 550 SC-002 550 SC-003 550 SC-004 550 DY-001 550 DY-002 550 DY-001 550 OU-001 550 OU-002 Script: #!/bin/bash Elogs=/home/elogs.txt ...
2
votes
1answer
35 views

Echo input text amount limit?

I'm trying to do echo "foo foo foo ....[many many lines of foo here] foo" > "/Users/myname/destination.txt" through Applescript, but it returns an error when the characters in the lines of foo ...
1
vote
1answer
67 views

Convert vertical array data to horizontal array data

I have a file with 25 matrices in a file, and each matrix is has 128 rows and 5 columns. Each matrix are putted one after the other, in a vertical way. Like this File input(file1): Array1 Array2 ...
1
vote
2answers
55 views

Bash redirection doesn't work for SQLite command

Bash allows for piping to stdin from another command in this way... $ ls /bin/aud* | cat /bin/audacity /bin/audiocompose /bin/audiosend ... ...and this way as well: $ cat <(ls /bin/aud*) /bin/...
1
vote
1answer
56 views

Install command if command doesn't exist [closed]

I have this set up in a Makefile. ARG_2 := $(word 2, $(MAKECMDGOALS)) command_exist=command -v $(1) >/dev/null 2>&1 command_not_exist=! command -v $(1) >/dev/null 2>&1 npmig: ...
1
vote
1answer
45 views

script ssh login to server and pass root password

I have written an expect script to automate the login process for ssh. My user account has rsa keys setup but once I log in I want to switch to root but the remote server is hanging on the password. I ...
0
votes
1answer
34 views

Can't remove apostrophes from filenames in terminal [duplicate]

I don't understand why zsh and bash (ls) show me lots of filename inside apostrophes, but not all: 'joe rilla - mauern fallen.mp3' jokaz-alarmbereit.mp3 'yoshi blessed - everybody free.mp3' I tried ...
-1
votes
2answers
89 views

How do I grab image dimensions using ImageMagick cli?

I am having issues with the part of the following script where it takes the inputted image and checks its dimensions. If it's not a certain dimension then it resizes the image. My issue is what would ...
0
votes
0answers
26 views

script to remotely change uids in linux [duplicate]

im writing a script to remotely change uids over ssh and it kinda works, but only the first pass through the loop works.. here is my script, #!/bin/bash<br> servers="server1 server2"<br&...
1
vote
1answer
37 views

Loop through read only .zip data archive to extract line from .kml file within [duplicate]

I am trying to access some satellite data on a read only archive. I am only interested in files with certain co-ordinates listed in a .xml within the zip that match my research area. There are ...
0
votes
2answers
38 views

What's the proper way to use a variable with spaces in part of a shell script command? [duplicate]

How can I include spaces as part of a variable used in an svn command for RHEL bash scripting? Or if there's something else wrong with the following, please advise. The SVN URL variable has no spaces,...
0
votes
1answer
37 views

How to save the grep o many files

I am using grep to catch a part of many files, which has name 001.log, 002.log, 003.log .... I need to save the grep as a different file grep -A3406 -P 'Molecular' *.log And to output the grep ...
2
votes
2answers
86 views

Use env with environment variables from file

Let's say I have a file (called e) with this content: a=3 b="5 6" How can I get each one to be interpreted as a separate argument to env? That is, to have it equivalent to: $ env a=3 b="5 6" ...
3
votes
2answers
31 views

Build a process substitution list for tee

I have a script like this which I use to broadcast commands to several instaces of the postgresql database CLI connected to several different servers. I'm using a hard-coded set of process-...
2
votes
0answers
24 views

Issue with adding a function to the .profile [closed]

I added the following to the ~/.profile: #Change desktop background f(x) function changeBackground() { FILE="'file://$(readlink -f "$1")'" echo changing to "$FILE" gsettings set org.gnome....
0
votes
1answer
30 views

How to use 7z and “for file” with multiple file inputs?

I have multiple files in a folder like: 1.txt 2.txt 3.txt ... 100.txt And I want to use 7z to compress single files, generating 1.7z, 2.7z 3.7z... I'm trying to use for file in {1..100} ./{1..100}....
1
vote
1answer
30 views

bash - aliased command - use original command? [duplicate]

I have ls aliased to ls and some flags, however, I want to use the original, 'vanilla' version of ls in another alias. Is there a way for me to call the original version of ls?
2
votes
1answer
50 views

How to choose the highest number element in many files with many arrays

I have many files which each one contain many arrays(like input 1 and 2, below). Each array has two element numbers in the second row. I need to use a logical criterion to choose the highest number ...
0
votes
2answers
40 views

Sum column numbers elements in many arrays

I need to sum the the numbers located in the same column in an array. The input is: 1: 6.1703 44 3.5 0.3 46 7.3 2.3 2: 6.1932 44 5.29379 2.9 46 1.72261 7.2261 3: 6.5664 45 4.756 5.6 46 1.6 2.5 4:...
0
votes
2answers
75 views

A do nothing line in a bash script

I have a bash script and I have an else statement which I want it to do nothing. What is the best way to do this?
1
vote
1answer
126 views

Why does ci" (change inside quotes) not work in bash with vi mode enabled?

My favourite way to use bash is with readline's vi mode, enabled with set -o vi. It works perfectly for me, except that ci" does nothing. The change inside X feature does not work. What can I do to ...
0
votes
1answer
41 views

ffmpeg bash script segment template

I was trying to control ffmpeg file segment function through a bash script to cut a large movie file into smaller pieces. I took a look at the documentation here but this doesn't really cover what I ...
1
vote
1answer
38 views

How to generate a set of new different files through shell scripting given a certain pattern name?

How to generate a set of new different files through shell scripting given a certain pattern name? Said I have this pseudocode: #!/bin/bash for i in {1..5} do ./processing < base.ppm > ...
1
vote
2answers
27 views

bash : export: `PATH:home/pi/netkit/bin:/usr/local … invalid indentifier [duplicate]

Currently I'm struggling with some notification every time I open terminal: bash: export: `PATH:home/pi/netkit/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:bin:/usr/local/games/:/usr/...
1
vote
1answer
37 views

cd to previous directories [duplicate]

I'm running CentOS 7, but hoping there is a general Linux way of doing this. So you can cd back and forth between the previous and current directory with this: cd - Is there I way can cd back ...
1
vote
2answers
37 views

Automatic backup and exclude of certain folders

I have created the follow bash script to be used in Cron for automatically backing up certain folders,...while also excluding certain sub folders: folders_to_backup=( "/fist/folder/to/backup/" ...
2
votes
1answer
40 views

Why doesn't grep give me the all found strings?

I have txt file whose inside there are 8 times "ATOMIC_POSITIONS" string and when I'm trying to write each one of them with ; AtomicPos=$(grep -n "ATOMIC_POSITIONS" hw1_out_si_wire.txt) echo $...
0
votes
2answers
33 views

How can I assign the last element of an array to a another array?

Let say I have an array $Info whose elements are ; ! total energy = -1090.13343774 Ry ! total energy = -1090.20757070 Ry ! total energy = -1090....
1
vote
1answer
47 views

Script to send mail using function

I am trying to write a bash script with a function which you use to send an email from the command line to an address and include a Cc address, a subject line, and an input file. For example, if the ...
1
vote
3answers
38 views

Extending Linux terminal Program [closed]

Any quick ideas on how to write a program that extends the terminal's basic functionality? I want to do everything the terminal does but additionally do some custom processing on whatever the user ...
2
votes
1answer
21 views

Strings from two distinct arrays not matching?

I'm trying to filter one array from another array. That is, I'm trying to create a third array with a logical not-intersection. The best I can tell, it appears this block of code never matches, and ...
1
vote
1answer
43 views

How to add numbers in many arrays

I have a file with many arrays, which has "identifiers" numbers in the first column. So I need to sum the numbers located in the second column based on that "identifiers" . An example of the input: ...
-4
votes
2answers
101 views

What is wrong in this code? [closed]

The code is ; cm=$1 nm=$2 case $cm in "out") declare -a en declare -a inf ec=$(grep -n "! " hw1_out_si_wire.txt) IFS=$'\n' en=($ec) lst=$((${#en[@]} -1)) IFS=' ' inf=($en[$lst]) echo " Energy: ${inf[...