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
0answers
34 views

I want to suppress “no access to tty” error message?

I have a bash script where I use ssh to connect to another server and run some commands there. I found some sites that the error (Warning: no access to tty (Bad file descriptor). Thus no job control ...
4
votes
1answer
36 views

Suppressing “sudo: sorry, a password is required to run sudo”

I am trying to test if a user has the required sudo rights to run a command as another user without providing a password. What I have is this sudo -u other-user -n true if [ $? -ne 0 ]; then ...
1
vote
1answer
31 views

Bash STDERR still appearing after redirection [on hold]

I am trying to parse the output of yum check-update in Bash 4 (Red Hat) and want to skip the first line that states: 'This system is not registered to Red Hat Subscription Management. You can use ...
3
votes
1answer
26 views

Bash ignoring my PATH and it's cache

I have installed pip in my ~/.local/bin/ directory. Here are the outputs of which, type and $PATH $ type pip pip is hashed (/home/bcc/pedros/.local/bin/pip) $ which pip /usr/bin/pip $ echo $PATH ...
0
votes
2answers
36 views

How to combine arithmetic expansion and brace expansion? [duplicate]

Can peoples combine arithmetic expansion and brace expansion? $ for i in {$((1 + 1))..5}; do echo $i; done; {2..5} $ echo "bash laughs at me"
4
votes
1answer
89 views

`seq` and bash brace expansion failing

IINM my system is failing when bashing for i in {0..10000000}; # Seven zeroes. do false; done # `bash` exited and its `tmux` pane/window was closed. or for i in $(seq 0 10000000); # ...
3
votes
2answers
82 views

Bash -c with positional parameters

Usually, $0 in a script is set to the name of the script, or to whatever it was invoked as (including the path). However, if I use bash with the -c option, $0 is set to the first of the arguments ...
2
votes
2answers
43 views

How to make bash script ask you if you want to execute the next segment(part)?

Soon as I execute the bash script. Given that I have set -x I will visually observe what is happening. But at certain parts, I want it to stop and ask me if I still want to continue executing the ...
4
votes
1answer
36 views

Bash script for scp interpreting tilde (~) too soon

So, I just started a new C++ class that requires me to program in a Linux environment. I don't have Linux installed on my machine, but I do have OS X and I can ssh into a linux machine in the lab at ...
0
votes
2answers
22 views

is there a way to escape a process in bash with out quitting it? [duplicate]

For example, I type sudo apt-get update and then a long list of stuff will come up for minutes.. if I want to escape from seeing this tiresome updating and take control of bash command line ...
1
vote
3answers
87 views

How to do command-line completion with files and folders

As a new Linux user, one of the things that's kept me away from the Command Line (CL) is that, for tasks involving files and folders (i.e. everything!), the amount of typing involved makes using the ...
1
vote
0answers
19 views

Bash tab completion fails inside of command substitution

I've been using kill $(pidof ) to terminate programs for a while, and since last night, every time I try to use tab completion inside the $() it throws an error, bash: unexpected EOF while looking ...
1
vote
2answers
31 views

profile.d on headless server

Is it a bad idea to put variables needed by a daemon program running at boot on a headless system in /etc/profile.d/? From my understanding profile.d doesn't get executed until someone logs into the ...
3
votes
1answer
50 views

Set Ubuntu System Proxy Settings without Restart from commandline

I am using Ubuntu 14.04 . I want to change the http proxy settings from the command line. This should be equivalent to changing in the GUI(All Settings->Network->Network Proxy) and clicking the button ...
1
vote
2answers
30 views

Restarting a service from a script

I have a init script - /etc/init.d/myservice, which starts some processes, including a CLI process. And from this CLI process, I am adding a command which can be used to restart the service (restart ...
2
votes
1answer
99 views

Sort the 'last' output by month

I know that the command last | tac is enough, but I want to do it using the sort command. I cannot sort it by column, it always sorts the first one only. Using bash on Arch Linux.
2
votes
2answers
67 views

find file, copy but with different name

I have files with random numbers in /home/user/files folder (every 4 days I have new ones). for example: john20 john25 john40 tom12 tom32 simon2 simon8 simon53 I want to take only last modified ...
0
votes
1answer
54 views

Intro to shell scripts with basic application: how do I set my computer to make an archive of a particular folder every day?

I've got a situation where I need to give some people access to my dropbox folder. Already so far they have deleted huge folders full of important data. Their computer skills could use a bit of ...
0
votes
0answers
37 views

Is there any suggestion to my bash script that (un)mounts an ISO file in order to make it better and safer?

I am new to bash script, and I wrote a script to mount / umount an iso file by detecting whether the /media/iso-file-name exists. Is there any suggestion for the script as below in order to make it ...
1
vote
2answers
31 views

Find out which process is in foreground on bash

I have a bash session open for which I have the PID, although I am not in control of the terminal (e.g. could be another user). This bash session has spawned some child processes. Is there any way to ...
2
votes
1answer
20 views

How to get clicked-on filename as argument of shell script triggered by this mouse-click

If, in Ubuntu's Nautilus, I click a midi-file, a window opens to specify an application for processing the file. Another option is a "user generated command" (UGC). (Let me choose Ubuntu, Nautilus, ...
2
votes
3answers
53 views

at job seems to be running using /bin/sh though I have a #!/bin/bash

I am trying to run a job using at, and I have a bash script (I do have #!/bin/bash as the first line), but the job fails because of use of [[ and ]] in the script, I see the following in the mail that ...
2
votes
3answers
134 views

Saving individual output lines into variables

I'm using find -mtime -2 to find files modified in the past 24 hours or less. The output looks like this. /home/user/logs/file-2014-08-22.log /home/user/logs/file-2014-08-23.log I need to save the ...
1
vote
1answer
39 views

Copy newest file in directory over SSH

How might one copy the newest text file from a particular directory on a remote server to his local machine? On the server itself I can do the following: $ cat `cd /home/user/dir ; readlink -f $(ls ...
2
votes
2answers
92 views

Why does Bash's “source” command behave differently when called from a function?

Given the following sourceable bar Bash script ... echo :$#:"$@": ... and the following executable foo Bash script: echo -n source bar: source bar echo -n source bar foo: source bar foo function ...
1
vote
1answer
61 views

How does bash execute an ELF file?

When I'm on my Linux Box I use bash as a shell. Now I wondered how bash handles the execution of an ELF file, that is when I type ./program and program is an ELF file. I grepped the bash-4.3.tar.gz, ...
2
votes
1answer
175 views

Running sh script: «Permission denied» despite the executable bit and root rights

I installed Debian in VirtualBox (for various experiments which usually broke my system) and tried to launch the VirtualBox guest addon script. I logged in as root and tried to launch autorun.sh, but ...
-2
votes
0answers
43 views

please let me know where to attach the files here? [on hold]

Below is the requirement. Ignore lines containing pattern "SET SNAP_ID" or "Shadow Copy Components:\" . Ignore lines with column 2 till 8 is empty. print lines containing pattern "Failed". ...
6
votes
1answer
72 views

Getting wrong $LINENO for a trapped function

I am writing a Bash script for myself to learn scripting. At some point, I need to add trap in order to clean unwanted directories and files if script is killed. However, for some reason I do not ...
2
votes
3answers
59 views

Script to ssh and run a command doesn't work

Below is the script. I wanted to login several servers and check for the kernel version. #!/bin/bash #input server names line by line in server.txt cat server.txt | while read line do sshpass -p ...
2
votes
1answer
16 views

ionCube shell script gives error

I have this shell script to install ionCube loader: if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root" ; exit 1 ; fi echo "Welcome to this script to install the ionCube loader on CentOS!" cd ...
5
votes
0answers
99 views

Echo difference between Ubuntu and Red Hat

I have mostly been experimenting with Ubuntu but recently was using a Red Hat Enterprise system and was surprised at a difference I found setting and displaying environment variables. In Ubuntu I ...
5
votes
1answer
20 views

Upstart and bash function names containing “-”

I inherited some bash scripts where the author used "-" in the function names instead of the more normal "_" e.g.: function a-b { ... } Ugly but legal in bash. Problem is I sourced this inside an ...
2
votes
3answers
50 views

Checking if an input number is an integer

I'm trying to check if an input is an integer and I've gone over it a hundred times but don't see the error in this. Alas it does not work, it triggers the if statement for all inputs ...
3
votes
5answers
150 views

efficient cross-os file size shell function

I'm looking for a simpler way to have a cross-os-unix file size check. I could use wc -c but I'm concerned the performance may suck on large files (I'm assuming it just counts chars and doesn't do a ...
1
vote
3answers
114 views

Calling a function which calls another function with a for loop

I am calling a function with a for loop and saving the returned value to a variable. When I run the code, I get a command not found error. What is wrong? #!/bin/bash check_1() { x_$1=$(check_2 ...
0
votes
2answers
36 views

how to pass a value to a variable that in a other variable

I am new to scripting. I am getting a "bad substitution" error while running this code. I want to print the values in h_1, h_2, h_3with a for loop. #/!/bin/bash h_1=12 h_2=13 h_3=14 for ((i=1; ...
3
votes
1answer
155 views

How do I fill my password automatically from .bash_profile when running command as sudo?

I know I could just put something like sudo mypassword in my .bash_profile, but I don't want to run every command as root. I want password to autofill under following circumstances: only the ...
3
votes
1answer
34 views

Error when calling a script from inside another script

I'm writing a couple of scripts to start vlc and periodically update its playlist. The update_pls.sh works well if I execute it from prompt, but when I call it from start_vlc.sh, in each for cycle I ...
-1
votes
0answers
17 views

Become root after login via plink from Windows host

I m trying to connect to a linux server from Windows host via plink. I couldnt figure out how to become root after logon. I have to login with ordinary user first as I can't change config of the ...
4
votes
3answers
61 views

How do I gracefully suspend and resume `cmd1 && cmd2 && cmd3` chain?

From the previous question it seems I failed to understand how && and ^Z interact properly: $ command1 && command2 && command3 Running command1 ... Running command2 ...^Z [1]+ ...
1
vote
2answers
74 views

aliasing a slightly complex script on Linux/bash

Stormvirux provided this nice script in another thread. It puts column headings on the output of an ls -l listing: #!/bin/bash { echo Permissions links Owner Group Size Last_modMonth Last_modTime ...
0
votes
2answers
69 views

change the extension of all files based on user input

I was taking an online assessment and I got the below question. Create a script located at /usr/local/bin/set-file-extensions that will change the extension of all files in the directory ...
4
votes
1answer
35 views

examine the exit code of processes launched in parallel from a script

Say I have the following bash script: #!/usr/bin/env bash process-1& process-2& process-3& I have two questions: how can I check at the end of my script that all processes exited with ...
2
votes
1answer
33 views

Why doesn't PIPESTATUS work on pipelines within a command substitution

Proof below: Bash 4 Prompt> $(echo hello|sed 's/h/m/'|xargs -I{} ls {} 2>/dev/null|sed 's/ /_/') Prompt> for i in ${PIPESTATUS[@]}; do echo $i;done Output> 0 Prompt> echo hello|sed ...
15
votes
5answers
1k views

Is there a way to tell sudo to set my username as owner for the files created instead of root?

If I do a sudo cp /etc/foo.txt ~/foo.txt, the new file is created with root as the owner. Right now, I see no way around this other than using the last two commands (ls to clarify use-case): ...
1
vote
1answer
25 views

Understand `compgen` builtin command

From help compgen: $ help compgen compgen: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word] ...
7
votes
2answers
240 views

Is there a shortcut for repeat the second proximate command in bash?

We all know that !! can repeat the last command you do in bash. But sometimes we need to do some operation like $ python test.py $ vim test.py $ python test.py # here is where I need to repeat the ...
0
votes
0answers
11 views

Determin if the currnet terminal has a dark or light theme [duplicate]

I have several (Bash) scripts that uses ASCII color codes. They look good on my dark themed terminal, however on my colleagues light themed terminal the colors I selected don't look that good. Is ...
1
vote
3answers
43 views

How to handle backspace while reading?

How do I handle the backspaces entered, it shows ^? if tried & how read counts the characters, as in 12^?3 already 5 characters were complete(though all of them were not actual input), but after ...