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

1
vote
1answer
15 views

option -n for pushd and popd

popd Remove the top entry from the directory stack, and cd to the new top directory. When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top ...
-1
votes
2answers
39 views

How to delete all the lines in a UNIX file except first and last line? [on hold]

I want to keep only header and trailer records in a UNIX file.
0
votes
0answers
4 views

SIPS changing padcolor to transparent in landscape

I am creating a bash script to automate the scale down and padding of a lot of images. The idea is this: whatever the image size is, if the image is portrait, scale the height to 960 and add a white ...
0
votes
3answers
33 views

Why does (` `) gives a list and $() gives only one argument

I might not word this properly, pls edit. Say I have: lst=(`ls $1`) echo $lst #this gives the first element of the list but then when I tried this: lst=$(ls $1) echo $lst #this gives me all the ...
1
vote
3answers
40 views

Find size of file in unix using for loop

I am trying to get the size of each file in a directory using a for loop, running the below script #!/bin/bash FILE=/home/cloudera/Desktop/new for file in $FILE do size=`du -b ${file} | cut ...
1
vote
2answers
47 views

Stop bash script with any key

I'm writing a custom gnome-terminal profile which I want to stop with any key I choose. After pressing the key, my intention is to complete all my commands at that moment and start su. I've tried ...
1
vote
2answers
15 views

Trying to direct variable contents into command gives Ambigious Redirect

I'm trying to write a script which tests the http response from various Node servers I have running and which then emails me if any respond with a 502 error from Nginx (meaning one or more server has ...
0
votes
2answers
44 views

using ls in bash

I have some files like this: a.10 a.15 a.20 a.30 a.40 a.50 if I want to do a same work for all of them I can use for data in `ls a*| sort -n` If I want to do same work one by one. I can use: ...
1
vote
2answers
19 views

bash adding a filename to an alias command [duplicate]

I have an alias to a ffmpeg command to start recording a session like this: alias sreq='ffmpeg -f x11grab -r 24 -s 1024x768 -i :0.0 -qp 0 -c:v libx264 -preset veryslow' I can just type sreq ...
8
votes
2answers
599 views

Can't use !$ in script?

Just wondering why this is not working #!/bin/bash ls /bin ls !$ I expect to run ls /bin twice, but the second one raises errors as !$ was not interpreted Did I miss something, or !$ only work ...
0
votes
0answers
18 views

Bash script in /etc/pm/sleep.d/ blocks suspension

I have a simple script on my ubuntu, which I placed into /etc/pm/sleep.d/. Here it is: /etc/pm/sleep.d$ cat 01_working_with_pulseaudio #! /bin/sh case "$1" in hibernate|suspend) ...
23
votes
1answer
1k views

ESC + { : What is it and where I can know more about it?

I was play around at the bash prompt, and pressed ESC followed by { , after which , the shell showed all the files for completion, in a fileglob string. Eg : If I had typed bash C followed by ESC+{ , ...
-2
votes
1answer
30 views

RaspberryPi- Bash entry explanation [on hold]

Can someone please help me with this entry i cannot figure out what it means. What does this entry mean: -rwxr-xr-x 1 root root 920788 Mar 28 2013 bash
0
votes
1answer
13 views

BASH script presenting IF syntax error

for k in {794..800} if [ -f "vesta_$k.xyz" ] then do mkdir $k mv vesta_$k.xyz $k/vesta.xyz cd $k/ <<COMMANDS>> cd .. ...
0
votes
4answers
60 views

bash : multiple command on one line with different exit code

I run a bash command from a c++ code using the system function provided in cstdlib. My question is not about the c++ implementation, but the one thing that is relevant to my question, is that I have ...
0
votes
4answers
31 views

Alias for listing top file and directory consumption - shortest way?

function isaix { echo "alias d='du -sm -- * 2>/dev/null | sort -nr | head -20'" >> ~/.kshrc; } function islinux { echo "alias d='du -sm -- * 2>/dev/null | sort -nr | head -20'" >> ...
0
votes
1answer
35 views

add 10 days for UNIX timestamps output

I've file contain many of epoch / UNIX timestamps need to add for example +10 days for output date so then I will get new date and I've create bash script with date command but seems doesn't work ...
0
votes
1answer
33 views

Unexpected end of file in .bash_profile

When I do source ~/.bash_profile I get this "line 14 syntax error: unexpected end of file" error, I tried to delete the last line for no avail. Thanks # Get the aliases and functions if [ -f ...
2
votes
2answers
42 views

What is the bigger difference in this case when using case or if?

I always use if for this type of stuff, and I haven't really thought of it, but lets say something simple like this: case $1 in test) echo "test" ;; test2) echo "test" ;; test3 echo "test3" esac ...
1
vote
2answers
31 views

legality of creating a variable for a file location

adapter= /Volumes/My\ Passport/Documents/adapters.fa Can I create this variable so that I can just refer to adapter for the exact file (and its location)?
0
votes
0answers
6 views

netsnmp sending traps on ping failure

Is there an easy way to send a SNMP trap on a event, i.e. one of my IP cameras goes down. The IP cameras do not have any ability to have a SNMP agent installed, but I have a script that checks if the ...
2
votes
2answers
26 views

Parameter expansion question

I have 2 files each in user/admin/1/2/[a-c] subdirectories. The files are preQC_1.txt and preQC_2.txt - both of which will be inputs in my tool. I use "${f##*/}" for preQC_1.txt in my for loop for ...
7
votes
2answers
367 views

Run a command before any terminal command [duplicate]

Is there a way to run one command before any terminal command gets executed? For example: > ls -ltr > "Hello you ran ls -ltr" //this is what I would like to achieve > ..output of ls -ltr ...
4
votes
1answer
26 views

Prevent customized bash autocomplete from affecting io redirection (< and >)

I've used complete -W 'firstdatabase databasetwo etc' mysql to save a list of databases, so that I can autocomplete them using the mysql command. However, in many cases I would type mysql db < ...
1
vote
1answer
25 views

Can Bash tell an interactive SSH session from an in-line SSH session?

I have a Bash script that needs to be run from an interactive prompt, due to environment variables and configuration that only seems to be read when actually logged into a session. Examples below: ...
2
votes
2answers
113 views

Bash: #: command not found

I just moved to Arch Linux with KDE a week ago. Everything worked well until I installed ibus-unikey and ibus-qt, after that, whenever I open konsole, this error appears: bash: #: command not found ...
1
vote
1answer
34 views

Linux + capture only the IP's from mount command

please advise how I can to print only the list of the IP's ( in the end of the lines ) , from mount output mount netapp64:/lunggg/OracleTeam/OracleCDs on /oracds type nfs ...
0
votes
2answers
86 views

For loop cannot distinguish * syntax

set -x for f in ~/1/2/*/*_1.txt; do subdir="${f%/*}" pushd "$subdir" &>/dev/null file="${f##*/}" expTool INPUT1= "${f##*/}" INPUT2= "${f%_1.txt}_2.txt OUTPUT1= "${f%_1.txt}_3.txt" OUTPUT2= ...
11
votes
5answers
279 views

How can I find the first missing directory in a long path?

Imagine I have a path that doesn't exist: $ ls /foo/bar/baz/hello/world ls: cannot access /foo/bar/baz/hello/world: No such file or directory But let's say /foo/bar does exist. Is there a quick way ...
0
votes
0answers
22 views

Comparing variables with string in bash [on hold]

I have following bash script. However its not entering the if block.What am I doing wrong? #!/bin/bash interface="TenGigE0/0/0/3" optics=`egrep -e "$interface\"" "/home/scripts/a.txt" | cut -d ":" ...
0
votes
2answers
27 views

Bash: split multi line input into array

I've got a file with strings and base64 encoded data over multiple lines, that are sepearated by a comma. Example: 1,meV9ivU4PqEKNpo5Q2u2U0h9owUn4Y8CF83TTjUNWTRQs7dEgVxnsMgf4lvg9kvxcIaM3yB4Ssim ...
1
vote
1answer
45 views

bash - queue subshells

function _abc { : 1 min task : _check & } function _check { wait for the previous calls of _check to complete : 15 mins task : } function abc loops depending on number of tasks. It is ...
1
vote
4answers
95 views

Bash prompt execute command every time a new prompt is displayed

I have the following prompt in bash which shows the current git branch: PS1+="$(git_prompt)" #git_prompt is a function in my .bashrc which works when I source the .bashrc, but not when I change the ...
0
votes
0answers
41 views

Bash concating strings don't work [on hold]

I have searched everywhere and tried a lot of possible option's found here and on Google but none of them seem to work. I have a script that loads variables from a config file and that works (if i ...
-1
votes
0answers
60 views

Understanding {1},{2},{3},{4}… parameter to parallel [on hold]

DISCLAIMER: I am using Mac OSX. The bash script is in a different directory from the files that require processing. From here my struggle begins… HELP 1: I have multiple files each housed ...
1
vote
1answer
40 views

generate file names in loop [on hold]

DISCLAIMER: I am using Mac OSX. The bash script is in a different directory from the files that require processing. From here my struggle begins… HELP 1: I have multiple files each housed in a ...
2
votes
1answer
42 views

change locale in script

I made an script that do some math, using bc and printf. It worked well under cygwin which locale is en_US.UTF-8, but when I run it under linux, which locale is en_ES.UTF-8, it fails because it uses ...
1
vote
1answer
37 views

Running a Bash expression from sudo

I can list my recent apt-get history with:- zcat /var/log/apt/history.log.1.gz I am trying to automate this for all history files. I tried: sudo for logf in $( /var/log/apt/history.log.?.gz ); do ...
3
votes
2answers
43 views

Read a password securely from within process substitution?

Related: Securely feeding a program with a password How to read from stdin in process substitution? Process substitution and cat: can't read stdin I've read the above questions and I still ...
0
votes
0answers
7 views

how to find keycodes for Aterm backspace, and deletekey

I downloaded compiled, and installed aterm 1.0.1. and I cannot get the backspace or delete keys to work. I've tried everything I've found on the net about it. aterm*backspacekey: \010 ...
4
votes
2answers
42 views

From bash, spawn two processes and exit both if either sibling exits

From bash, I am spawning two processes. These two processes depend on each other. I want both to exit if either one dies. What is the cleanest way to do that? Currently I have the following: # start ...
2
votes
1answer
71 views

Strange bash script behaviour

I have two bash scripts, which are binary identical, have the same permissions, are unique on my drive and are not found in sudoers. Still one passes the uid test for root, the other one not. If I ...
3
votes
1answer
39 views

Echo text as suggested prompt in bash

Is it possible to change text that appears after $PS1. It is what user inputs. I want to suggest some command hereafter my_function is run. Of Course I should be able to modify/delete it using ...
0
votes
3answers
24 views

Implementing a command that executes the given command in a certain path and returns to the current path

my code: execInPath() { prev_dir=${PWD##*/} cd $1 shift res=$($@) cd prev_dir echo res } alias path=execInPath $ path ~ ls gives: bash: cd: prev_dir: No such file or directory (and the files in my ...
1
vote
2answers
38 views

Copy output of curl to file

I'm running raspbian and using this bash script to take a photo every minute and upload it to my FTP server: #!/bin/bash while [ 1 ]; do DATE=$(date +"%Y-%m-%d_%H_%M_%S") raspistill -q 10 -th none ...
0
votes
4answers
48 views

Find files using shell script

I have the below script which looks for the file in the current directory and evaluates to true if the file exists in the directory and evaluates to false if it does not #!/bin/bash printf "\n Please ...
0
votes
1answer
23 views

Using if and find together

I'm trying to write a script that echos "success" if it finds .trc files older than 5 days in a directory. However I'm getting a full_path_trace': No such file or directory error even though my ...
0
votes
0answers
34 views

Bash script is not executing after reboot command Ubuntu 14.04

I've tried using a /etc/init.d/ script, an upstart script, crontab, etc. None of the above are causing the script to execute on boot. The service I am attempting to automatically start on boot is ...
1
vote
1answer
35 views

Read each line - BASH

my goal is to store each foliated line (actually each rule) into an array. My output: Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT ...
0
votes
0answers
28 views

Process being stopped randomly

I made a script to manage a TS3 server. The script runs 'cd '.$ts3location.';/bin/bash '.$ts3script.' status' where $ts3location is the full directory to the server and $ts3script is ...