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

2
votes
2answers
47 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
57 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
23 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
100 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
22 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
34 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
80 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
33 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
107 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
77 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
0answers
39 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
33 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
21 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
57 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
139 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
40 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
107 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
69 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
194 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 ...
6
votes
1answer
76 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
73 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
19 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
116 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
23 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
54 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
156 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
116 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
37 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
165 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
20 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
65 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
73 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
35 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 ...
16
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
27 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
48 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 ...
1
vote
1answer
34 views

How could i flip content of a binary file with bash commands

I was wondering if it's possible to do bitwise conversion on a binary file, with bash commands, (in my case bitwise negation).
3
votes
2answers
53 views

Disable bash's cache of executables in the path

On the rare occasions that I notice bash's cache of things that it has found in the path, it's not because it's helpful, it's because it's bloody annoying. An example: ~ dc$ export ...
2
votes
3answers
46 views

bash: dynamic environment control

I have an application which modifies environment variables. The intent is to launch a bash shell with a modified context-specific environment. When my application modifies the environment, and ...
1
vote
1answer
94 views

Reboot when no network connection does not work!

I have a Raspberry Pi that I use as a NAS for my local network. It works fine, but when I turn off the router to which the pi is connected, it permanently loses the connection. To be able to connect ...
1
vote
1answer
73 views

Command-line parameters in bash script not recognised

I use Debian (Raspbian) Wheezy. If this command line works fine: smsd -c sms/out -i 60 -0 -f sms/smsd.log and this alias also works fine: bsmsd='smsd -c sms/out -i 60 -0 -f sms/smsd.log' then ...
4
votes
3answers
50 views

Is it possible to view the list of file names of a zip file which is inside another zip file?

I know I can use unzip -l file.zip to view the file list of a zip file. But a got a zip file inside another zip file. I tried unzip -l file.zip/sub_file.zip, but failed. Is it possible to view the ...
11
votes
3answers
835 views

How to eliminate annoyances when starting a GUI from a terminal?

I prefer to launch GUI applications from a terminal window rather than by using a graphical desktop. A frequent annoyance is that often the developers haven't anticipated this type of use, so the app ...
0
votes
2answers
44 views

How do I validate a settings(ini) file for the values expected using bash?

After I check if the ini file exists where it is expected to be, which I've learned how to do, I would like to check the file for proper formatting. I'd like to validate any number of "site" entries ...
1
vote
2answers
24 views

Remove all files without a keyword in the filename

I have a list of files in the following fashion: > file1.jpg > file1_orig.jpg > file2.jpg > file2_orig.jpg I want to keep all the files with the extension _orig.jpg and discard those ...