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
1answer
662 views

Bash While loops

I have a loop set up like the following #!/bin/bash cat $1|while read line;do wget --limit-rate=50k http://url/$line.json -O got-$line; if [ "$?" -ne "0" ]; then rm got-$line; fi ...
2
votes
3answers
179 views

Bash - setting environment vars from bash invocation line

I'm looking for a way to manipulate some env var, which will be available for processes spawned by bash. Something like the below (of course, the syntax is not correct) /bin/bash VAR_X=2 and then ...
3
votes
1answer
521 views

Color script output only when invoked from interactive shell

I made a bash script producing colored output. The colors are fine when the script is called from an interactive shell. However, if the output is processed in another script, or passed through a pipe, ...
8
votes
3answers
864 views

Bash: Capture / Use last (or Nth) line in stdout

Query I use Bash. When I'm looking for files, often I'll do the following: find -name stackexchange.hs And often the results will look like: /youre/the/man/now/dog/stackexchange.hs ...
3
votes
1answer
246 views

Printing the line after or before a regular expression match in Bash

Given a string like the following: BASH - Mplayer Playlist Shuffle http://www.youtube.com/watch?v=IB7SCPtbJM8 metalx1000 BASH - Playing Music http://www.youtube.com/watch?v=S_-EGoLYCXY metalx1000 ...
2
votes
2answers
272 views

How to read by multiple lines instead of line-by-line

I see that in my code I can modify a line if the entire code is based on that line. Example: <p class="example">this is an example Happy Holidays</p>. However if the </p> tag is ...
3
votes
2answers
654 views

Why do I have to use sh to execute scripts from CD/DVD media?

I hit again on this strange behaviour of the system. I'm running Debian 6.0.6 and had quite some troubles executing a script directly from CD/DVD. Finally I had to use: sh /media/cdrom/command to ...
3
votes
4answers
2k views

bash string extraction

I would like to extract the 2nd field from the last part of the following strings: foo_1.103.debug_xx.ver21-inc-1 --> string extracted "debug_xx" foo_1.103.1.0.release_32_xx.ver21-inc-1 ...
6
votes
3answers
302 views

Display the function body in Bash

I have setup several functions in my .bashrc file. I would like to just display the actual code of the function and not execute it, to quickly refer to something. Is there any way, we could see the ...
2
votes
1answer
2k views

Bash variable in Awk script

I have this flat file database(ff_servers.db) with following contents: 192.168.154.2 Alaska hp 192.168.157.3 Colorado dell 192.168.156.3 hawaii hp From command line, I could run: awk ...
4
votes
2answers
1k views

Convert file path to URI in bash

How can I convert a file path to an URI in the command-line? Example: /home/MHC/directory with spaces and ümläuts to file:///home/MHC/directory%20with%20spaces%20and%20%C3%BCml%C3%A4uts
2
votes
1answer
554 views

How redirect input while process is running?

I have an interactive application that takes input from the keyboard. Whenever I run the application I always write the same things in the beginning. So I was thinking I could make a file with those ...
3
votes
1answer
2k views

Why won't my bash script exit after execution?

I compiled a short bash one-liner to focus a running application or launch it if it isn't running: #!/bin/bash #intellilaunch.sh wmctrl -a $1 || $1 & disown exit 1 The command exits perfectly ...
2
votes
1answer
3k views

Bash restricted Shell using rbash

I am using /bin/rbash for some users. It's working as expected but there is some hack like when users run bash or dash, then they got unrestricted shells, so to avoid these commands, I have added ...
4
votes
2answers
862 views

how to use grep for specific files?

for example I type ls -altr | grep "23 Dec" so it will show files for 23 Dec only and I want to use grep for them, like ls -altr | grep "23 Dec" | xargs grep -l "some_string" but this doesn't ...
11
votes
2answers
5k views

How to unset set -o vi?

I wanted to try vi mode in bash but now I would like to change it back to normal. How can I unset -o vi ?
2
votes
2answers
2k views

How to use “fuser” to get process list for nested folder while using with parent folder as argument?

I am using fuser command to get the list of processes accessing a folder. However if the process is working on a file present in a inner folder, executing fuser command on the parent does not provide ...
3
votes
2answers
993 views

print message on terminal as well as /var/log/messages using logger

I used below options in script to print on terminal as well as /var/log/messages echo "System Load is OK : $Current_loadadv" echo "System Load is OK : $Current_loadadv" | logger but how can i do ...
3
votes
1answer
1k views

mkdir multiple directories with a subdirectory name having space in it

I want to make multiple directories in one go. The problem is that one of the sub directories have a name with a space in it. The directory structure i want to make is as follows. project /level ...
4
votes
6answers
7k views

CentOS | [root@hostname] does not show anymore?

For some reason I logged into my CentOS6 server and at the beginning of every line it normally shows [root@hostname]# Now it shows -bash-4.1# What does this mean? And how to I get it back to ...
2
votes
3answers
11k views

print output to 3 separate columns

MYPATH=/var/www/html/error_logs/ TOTALFILE=$(ls $MYPATH* | wc -l) FILETIME=$(stat --format=%y $MYPATH* | head -5 | cut -d'.' -f1) FILE=$(ls -1tcr $MYPATH* | head -5 | rev | cut -d/ -f1 | rev) ...
4
votes
4answers
446 views

Delete backward until met a char, like alt + bksp

Say my current line was: /tmp/path/to/file:123 Now I'm at the end of this line, now I want to delete :123 by pressing some key combination, was that possible? (colon was merely mentioned as an ...
2
votes
3answers
3k views

How to change the output redirection of a running process?

I know how to redirect output and how to suppress them in bash. Now, suppose I accidentally forgot to append the output redirection part to the command (e.g. 2>&1 or > /tmp/mystdout) and my ...
7
votes
4answers
5k views

Preserve directory structure when moving files using find

I have created the following script that move old days files as defined from source directory to destination directory. It is working perfectly. #!/bin/bash echo "Enter Your Source Directory" read ...
9
votes
6answers
2k views

How to copy every 4th file in a folder

I have a lot of files in a folder, named like 00802_Bla_Aquarium_XXXXX.jpg. Now I need to copy every 4th file to a subfolder, saying in selected/. 00802_Bla_Aquarium_00020.jpg <= this one ...
0
votes
3answers
910 views

How to remove/rename file which contains special character eg. “-x” using command line [duplicate]

Possible Duplicate: What does “--” (double-dash) mean? Can anybody explain me below things i have file named "-xyz". if i try to remove or move that file using command line , it's unable ...
2
votes
2answers
177 views

Does a parent bash script remember the cd history from a child bash script?

Example: mainscript.sh cd /mnt/something ./buildscripts/000-script.sh 000-script.sh cd /mnt/otherthing mkdir something exit
5
votes
2answers
1k views

Bash prompt not recognizing Unicode escapes

I'm trying to customize my Bash prompt with Unicode characters and I'm having a bit of trouble. If I try to include a Unicode character like this: $ echo ☢ | hexdump -C 00000000 e2 98 a2 0a ...
2
votes
2answers
538 views

Is there any way to test out PS1 Bash Prompts before committing them?

I'd like to mess with my Bash prompt, but I'd like to do so in a way that doesn't corrupt my already extant one. I could just comment it out, but is there a way to test it either with an online tool ...
1
vote
1answer
138 views

how to add a description in footer

I enjoy learning how to modify files with awk, sed, and bash. However, I know it could cause issues down the road and I would like to be prepared with a log inside the file. I was thinking about how ...
9
votes
2answers
3k views

echo vs <<<, or Useless Use of echo in Bash Award?

By now the Useless Use of cat Award is very well known, and there's also a mention of a Useless Use of echo (not relevant for this question). I'm wondering if there should be a "Useless Use of echo in ...
2
votes
1answer
79 views

required output not achieved by bash script

I am new to bash script and want to create bash script that moves some days old files between source and destination as per days defined in script. #!/bin/bash echo "Enter Your Source Directory" ...
3
votes
2answers
4k views

Read a file and copy to another file

I'm having a issue, I need to copy the file contents and remove a couple of lines if they match the output from a previous command. But so far, I'm having an issue in maintaining the file lines ...
-1
votes
1answer
164 views

Error while running bash script that moves files

I am new to bash script and want to create bash script that moves some days old files between source and destination as per days defined in script. When I run this script I get error find: paths ...
2
votes
2answers
474 views

Script to convert filenames to lowercase depending on extension

Script to convert filenames to lowercase depending on extension
5
votes
4answers
468 views

Accidental `nano SomeFile | uniq` renders the shell unresponsive

In my attempt to get unique entries (read lines) out of a simple text file, I accidentally executed nano SomeTextFile | uniq. This "instruction" renders the shell (bash) completely (?) ...
2
votes
3answers
248 views

Zip output formatting

I'm learning zip and I have run into something I cannot figure out in man zip. When I run zip -r $folder $folder it will correctly zip all contents but the zip contents is as follows: zip |-folder ...
0
votes
1answer
922 views

Where to find printf formatting reference?

Where is the offline reference of the format specifiers (e.g., %i, %s) which are supported by the Bash/system printf command? I've looked in help printf, man 1 printf and man 3 printf without luck. ...
6
votes
1answer
660 views

Running parallel bash jobs on a HPC cluster using GNU parallel

On an HPC cluster I am trying to run multiple bash scripts (permute2.sh) from 1 bash script using GNU parallel, however it doesn't complete every job. It randomly completes one job, while it is stuck ...
2
votes
1answer
230 views

Delete every users from a group

I search a clean way to delete every users from the 'sudo' group. On several distributions the user created during the installation process has sudo rights, I don't want this. I search for an ...
2
votes
2answers
532 views

Awk to output read file

I havent stepped into awk yet but it is on my plate for learning this coming year. I asked a previous question that led me to awk and it works. However, I am unsure how to input all file types and ...
5
votes
5answers
186 views

How to create directory ranging from 1 to nth?

In my scenario, I have some photos and I want to keep them seperate. At present I am doing mkdir gallery1 gallery2 gallery3 gallery4 gallery5 gallery6, this is a pain. I think we can do it easily as ...
0
votes
1answer
139 views

Where can I find historical documentation for bash?

Are there any sources for documentation for old versions of some GNU software, in this case particularly bash? I have a embedded system that is running bash 3.00.16, and I'm trying to do some shell ...
2
votes
4answers
410 views

Remove large chunks from json using vim

I have a huge file (1/2 million lines) of json. I need to delete a set of entries that contain a certain string. { "bla1": { "Part1": "Plop1", "Part2": "Plop2", "Part3": ...
0
votes
1answer
1k views

Bash script to copy *.log files into a new directory

I have some files like this: 2012-12-17_083213_1.log 2012-12-17_083213_1.log_stats 2012-12-17_083213_1.logaccount_ptr 2012-12-17_083213_1.loginitial_ptr 2012-12-17_083213_1.logptr ...
16
votes
4answers
19k views

How to view the output of a running process in another bash session?

I have left a script running on a remote machine from when I was locally working at it. I can connect over SSH to the machine as the same user and see the script running in ps. $ ps aux | grep ...
5
votes
3answers
217 views

Coloring output of forked processes

I have a runscript that starts some processes and sends them to the background mongod & pid_mongo=$! redis-server & pid_redis=$! # etc. All these processes then output concurrently to ...
1
vote
5answers
2k views

Identify folder in bash

I was trying to learn how to identify only folders within a folder on the main level. example: main -folder 1 -folder 2 -folder 3 I started with this script: #!/bin/bash ...
3
votes
2answers
1k views

Environment variable set but not respected

I find the following behavior a little confusing, can someone please explain why it happens? In /etc/bash.bashrc I have: EDITOR=vim And it is indeed set: lev@home ~ $ echo $EDITOR vim I would ...
4
votes
2answers
3k views

Shellscript to print a directory tree and files's contents with a nice presentation

I'm trying to write a shellscript which prints a tree-view for a specific directory and it's subdirs to pdf via latex, as well as the titles and contents of all scripts contained within that primary ...