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

8
votes
0answers
213 views

how to get exit status from the command before the last [duplicate]

I have solaris machine ( solaris 10 ) please Look on the following simple commands (haconf -makerw | grep -iq "Cluster already writable") # haconf -makerw VCS WARNING V-16-1-10364 Cluster ...
5
votes
3answers
703 views

difference between .* and * in regular Expression

I've a file named "test" that contains linux Unixlinux Linuxunix it's linux l...x now when i use grep '\<l.*x\>' , it matches : linux it's linux l...x but when i use grep '\<l*x\>' ...
2
votes
2answers
76 views

xinput - Ctrl+<Left> misbehaves if history-search-backward is mapped

I am using these lines in my ~/.inputrc: "\e[5~": history-search-backward "\e[6~": history-search-forward With these settings when I type c on the prompt and do a PageUp, bash only shows command ...
5
votes
1answer
277 views

Execute multiple bash commands on the output of find

I want to execute some commands using the find -exec option, but I'm not sure what' wrong with this code. Currently, it's only processing the first find result, then getting stuck. I'm using bash in ...
1
vote
2answers
246 views

What does the -c option of sg do?

What does the -c option of sg do? At least on my machine, the man page fails to explain this option.
2
votes
3answers
5k views

Using bash shell function inside AWK

Is it possible to use bash function inside AWK somehow? Example file (string, int, int, int) Mike 247808 247809 247810 Trying to convert values from decimal to hexadecimal. Function defined ...
2
votes
6answers
2k views

sort ls output by users

On Linux, is there a way to sort ls output by users? What I try to achieve is something like this: user_a   file1 user_a   file2 user_b   another_file user_c   this_file user_c ...
10
votes
5answers
722 views

How to detect from script when the user's desktop is loaded?

I have a deamon, implemented in bash and running by means of cron and the @reboot option, that shows the desktop in inactivity. The script is as following (timings are short for testing purposes): ...
3
votes
2answers
15k views

How to avoid the need to issue “y” several times when removing protected file

I'm looking for a solution to be used as a response to "rm: remove write-protected regular file [x] ?" I was thinking of issuing a character followed by carriage return for several amount of times, ...
8
votes
3answers
7k views

Count number of lines of output from previous program

I'm trying to count the number of lines of output a certain program produces. The problem is, the program takes a long time to run, and I want to display the output to the user. Is there a way to ...
1
vote
0answers
152 views

rsstail Not Printing Output

I've installed rsstail 1.8 on my linux box and everything seems to be going smoothly, knock on wood, except for the part where rsstail isn't printing the streams. Running the command, I see that it's ...
4
votes
1answer
1k views

Pass colors from ls through pipe to awk 'print' statement

This is a follow-up to my question from yesterday, Show sum of file sizes in directory listing. Thanks to Zero Piraeus and a point in the right direction by Mauritz Hansen, I now have function ...
1
vote
1answer
393 views

Guide/help using Dialog with bash scripting

While I understand how to create menus, no guide I've found teaches how to actually link them to commands I was hoping to have something like: dialog--clear --title "n00b's spellbook" \ ...
4
votes
3answers
385 views

Why should 'Character Classes' be preferred over 'Character Ranges' In Shell (Bash)?

The Linux Command Line (Book - page count 47) says: ... you have to be very careful with them [character ranges] because they will not produce the expected results unless properly configured. For ...
0
votes
1answer
413 views

svn backup bash script errors

I have created bash script for create dump of svn repositories. I want to add such functionality that after dump of every repository script send it to remote server using rsync and delete from dump ...
14
votes
10answers
43k views

Show sum of file sizes in directory listing

The Windows dir directory listing command has a line at the end showing the total amount of space taken up by the files listed. For example, dir *.exe shows all the .exe files in the current ...
1
vote
0answers
3k views

Using sshpass, return code (exit status) differs for reasons unknown using valid commands

There are a few things going on here but I think ultimately, either CLish or SSH is returning an exit code that is messing up my work flow. I'm attempting to connect to a remote machine (CLish shell) ...
2
votes
5answers
374 views

Command substitution - single quotes and spaces

How can I make command substitution pass a list of single-quoted POSIX paths separated by spaces? command1 $(command2) command1 '/path/to/file 1' '/path/to/file 2' '/path/to/file 3' How can I trace ...
3
votes
1answer
62 views

Is there an easy way to change bash suggestions?

I've noticed that some console commands (like sudo or xargs) are using different kind of suggestions when I press Tab (they suggest programs instead of files). Is there a way to mimic that kind of ...
0
votes
2answers
116 views

Supress expansion of * in echo

I am working on a script which dynamically executes some queries on daily basis. These queries are coming from a table in the database. Here is the sample output of the query table: ...
-1
votes
1answer
1k views

zsh: Is it worth the switch from bash? Is it the time? [closed]

I have been a bash user for years now. However, I find that zsh is increasingly gaining momentum. I came up with the following questions: Is zsh really becoming that popular? Will it compete with ...
3
votes
1answer
352 views

bash: different output between CTRL-C vs “ordered cleanup”

I really tried to find a better title for this question. I am open for suggestions. I've written a bash script that traps EXIT and calls a function if that signal is received. It calls the same ...
1
vote
2answers
280 views

How to print shell variables and values to be able to copy/paste them?

In Bash 4.2.25, the set and env output is not escaped, so shell escapes and any non-printable characters won't be copy-pasteable. Take for example this shell session: $ export foo=$'a\nbar=\baz' $ ...
0
votes
2answers
1k views

How to convert multiple XCF files to PNG?

I have a folder with a lot of xcf files which I want all to be converted to png files, at best via a one-liner from bash. How can I achieve such a task?
3
votes
3answers
967 views

Can't process stdout with pipe as it comes

I'm running tshark on a fifo, and the following is a bare example of a loop that prints the output of tshark as it comes: tshark -i $fifo | while read line; do echo $line done The problem ...
5
votes
2answers
239 views

Reference prior command output / terminal screen contents in current command line

I often need to copy an output line in Bash in its entirety: $ grep -ilr mysql_connect * httpdocs/includes/config.php httpdocs/admin/db.php statistics/logs/error_log $ vim ...
-3
votes
1answer
276 views

Paths in my bash profile do not work!

export PATH=/usr/local/bin:/Users/rodrigoprugue/Desktop/CRUNCH:~/phreeqc/bin:$PATH export PARFLOW_DIR=~/parflow/parflow.r605/ export SILO_DIR=~/parflow/silo-4.7.2/ export ...
1
vote
1answer
413 views

Safely convert unicode strings to printable characters

I have many HTML files containing mixed unicode strings like \303\243 and printable characters like %s. What I'd like to do is converting the unicode strings into printable characters in a safe way. ...
3
votes
1answer
2k views

Opening a usable xterm window through bash script

I often have projects for which I need multiple terminal windows open at different locations, and setting up my workspace each time I want to work on this project takes a long time, so I'd like to be ...
2
votes
2answers
60 views

How can I set a bash alias that evaluates $() when run?

I set up an alias: alias gpgagentexport="eval $(cat ~/.gpg-agent-info) ; export GPG_AGENT_INFO" However when I source my .bashrc the $(cat ...) is evaluated at that point. But I want to evaluate ...
2
votes
2answers
503 views

what is the difference between if and [[ in bash?

I see that if cmd then echo Hi fi works differently from if [[ $(cmd) ]] then echo Hi fi So what happens when there is a [[ and when there is not?
2
votes
3answers
354 views

Open multiple files in Vim with a filelist

I have a file 'filelist' that contains the following lines: text1.txt text2.txt text3.txt I am looking for a command line invocation that opens the 3 files in vim. I tried the following: $ cat ...
4
votes
1answer
538 views

Prompt for confirmation for every command

I'm writing a pretty ad-hoc install script for some thing. No much control constructs, basically just a list of commands. I'd like the user to confirm each command before it gets executed. Is there a ...
0
votes
1answer
49 views

Why are bash_completion scripts persistently in environment?

I accidentally typed the command export into my console emulator (running Bash) instead of export -p, and now all the bash_completion scripts are persistently in my environment, even surviving reboot. ...
1
vote
2answers
258 views

bash if statement behaviour question

I wrote this following piece of bash script. if [ $(tmux has -t junk) ] then echo zero else echo one fi It always returns one, no matter if the session exists or not. I checked in the command line ...
4
votes
4answers
1k views

Detecting X session in a bash script (.bashrc etc.)

Recently I put xset b off to my .bashrc. Now I'm annoyed by the error thet pops up when I log in via tty or via ssh, i.e. outside X session. First thing that came in my mind was [[ -z "$SOME_VAR" ]] ...
2
votes
1answer
380 views

Execute commands coming from a serial port

I have some hardware that is sending commands over /dev/ttyACM0 every once in a while and I'd like to execute them in a terminal. For example, if the ascii "ls" comes over /dev/ttyACM0, I'd like to ...
3
votes
1answer
405 views

How to prevent killing the X server with CTRL+C using bash traps?

On my Debian Wheezy system, I used to start my X session with the startx command. My .xinitrc file is: exec /usr/bin/awesome --config /home/cscs/.config/awesome/rc.lua >> ...
5
votes
2answers
6k views

What's the diference between comparison inside if using two or a single equal (=)

Read that for comparing string inside if we need to use double square brackets. Some books says that comparison can be done by =. But it works withe == also. #!/bin/bash a="hello" b="world" if [[ $a ...
1
vote
2answers
160 views

How do I get a field in bash's job list using awk?

I wanted to write a function to retrieve a field from the list of background jobs in bash. For example to get a specific argument. Let's say I send vim to the background, so "jobs" displays this ...
2
votes
2answers
1k views

How do I set bash aliases and variables from within vim?

In cmdline mode, the following examples do not work for me. !alias lol='echo lol' !lol='echo lol'
0
votes
2answers
62 views

Command in a variable [duplicate]

I am trying to run a statement where the name of the command is in a variable. For example: my_command='/path/to/some/command' $my_command -f foo -b bar -s something else But the above does not ...
2
votes
1answer
909 views

How to create a password protected shell script [duplicate]

How can I create a password-protected shell script for read/write access. It should also be executable by all users without the password. I have sensitive information in the script.
1
vote
1answer
209 views

Display ONLY IP addresses of currently logged users

I want to get a list of the currently logged users and their respective IP addresses. I tried the following command line: w -s However, the TTY, IDLE and WHAT columns are also displayed. I don't ...
1
vote
3answers
677 views

Why is this Bash command using regex not replacing my brackets?

I have this command to go through all my files in my Music directory, and all subdirectories, and replace any square brackets in the file name with rounded brackets: find /home/Music/ -depth -name "* ...
2
votes
2answers
432 views

Strange crontab-script interaction (bash)

I'm running Ubuntu 12.04 and bash. I've written a pair of shell scripts that allow me to set an alarm which, after ringing, unsets itself. The first, alarmset, allows me to enter a time and modifies ...
1
vote
1answer
1k views

What is a sure fire way to find all files and/or path that contains 2 keywords?

I was doing a find . -iname '*sitesearch*' | grep demo because I know the file should be some/path/SiteSearch/demo/SiteSearch.html, but it turned out a person put the file in as ...
10
votes
5answers
1k views

Can I select only one result from a bash glob?

I'm trying to write a script for work to automate some reporting on an output. The Log files are (currently, it's being 'standardise' in the future) stored in this sort of path structure: ...
7
votes
1answer
5k views

Delete whole argument in current bash command-line

Using ^W (unix-word-rubout) I can easily delete a single "word" from the current command in my bash shell. However, when dealing with quoted arguments that contain spaces (or unquoted arguments ...
1
vote
2answers
249 views

What is the meaning of this test expression

I have been reading the man pages for test(1), bash(1) and dash(1), but I can't figure out the meaning of this test : [ `echo hi` > /dev/null ] According to the man pages, there are two types of ...