Bash is a free shell for Unix-like operating systems from the GNU Project.

learn more… | top users | synonyms

4
votes
3answers
6k views

Move a range of numbered files?

I've got 291 numbered files (starting at 001 - title and ending at 291 - title) that need moved into separate directories. (001 to 021 to folder 1, 022 to 053 to folder 2, they aren't necessarily the ...
0
votes
3answers
117 views

Multiline && combinator operator for command chaining in batch file

I see that this operator is used in windows (and might be Linux?) to chain/combine multiple commands in one line. Commands are executed one after another, as long as preceding complete successfully ...
0
votes
2answers
46 views

How to tell what are my startup files for sh or bash?

From this question I understand that depending on the operating system sh and bash behave differently. Doing env and alias I can tell that: Every time I open a OSX Terminal or run bash the variable ...
1
vote
1answer
33 views

How to use unlimited list of arguments to a command in bash shell?

I'm running up against the "argument list too long" problem using a command in the shell (bash in my case). Most suggestions for working around this suggest using find or some variation, presuming ...
1
vote
3answers
80 views

How to use grep or awk to save every line from text file as new file?

I am a scripting beginner. What i am trying to do. I have a text file that looks like this (example): hello hi there apple I am trying to make a script that saves every line as a separate new file ...
0
votes
3answers
607 views

Virtualenv for bash

I really like virtualenv when working with python code and am wondering if there existed some tool which could emulate some of it when working in bash. What I want is some cleanly reverseble way of ...
14
votes
5answers
33k views

command not found when using sudo

There are a few question on the site that seem related to my problem but I could not find a solution in any of them. My operating system is Ubuntu 12.04. I have mvn installed in ...
4
votes
2answers
561 views

Bash autocomplete for different directories

I've played with bash autocomplete now for a while, but couldn't find a solution for my problem. I have a project directory with subfolders like this: projects/ruby/project1 projects/ruby/project2 ...
0
votes
1answer
26 views

Particular bash bc usage not storing result in variable

Unfortunately this result in a empty variable, and bc command print its result to terminal anyway while trying to attribute to aux aux=&(bc -l <<< "scale = 5; ...
1
vote
0answers
60 views

Shell Commands not working : REDHAT

I added some service to the startup script and then after reboot , i got this message- 24 package(s) needed for security, out of 52 available Run "sudo yum update" to apply all updates. -bash: id: ...
2
votes
1answer
49 views

Execute command after broken SSH connection

Is there a way to execute a command after an SSH connection is broken (blackout etc.)? When I normally log off I can just use .bash_logout but I don't know what to do when my connection breaks.
1
vote
2answers
41 views

Is there a way to make my .bash_profile load the contents of my .profile file?

I was using a .profile quite happily for two years on my Mac now running Yosemite. A recent brew install created a .bash_profile and whilst my .profile still exists, it is now no longer loaded. I ...
0
votes
1answer
31 views

Why does my vim colorscheme stay after I close vim?

I recently used vundle to install the solarized theme for vim on my Arch Linux machine. Whenever I open vim, the theme is applied, but it stays applied to my terminal window after I close it. I can ...
0
votes
1answer
34 views

Error while trying to execute cron script with space in path

I have a script with several rsync commands in it. The script file is placed in an NTFS partition with owner and group permissions set to root. I have no problems running the file manually from the ...
21
votes
4answers
22k views

I want to change DPI with ImageMagick without changing the actual byte-size of the image data

In GIMP there is a very simple way to do what I want. I only have the German dialog installed but I’ll try to translate it. I’m talking about going to Picture -> PrintingSize and then adjusting the ...
1
vote
1answer
81 views

Can't find the good Cygwin shell executable

I am working on Windows 7 and I need Cygwin for my project. I am trying to launch the Cygwin terminal from a Java programm and then write command lines but my problem is that I can't find the right ...
0
votes
1answer
93 views

Changed cygwin home location, now the terminal can't find my .minttyrc config file

I had to change the HOME location for Cygwin by setting it to pick up the directory I set in /etc/passwd (following the solution from here). It seems to not be a problem for the majority of my ...
1
vote
1answer
17 views

Using strace, how do I use it to get the network and serial calls

I have a python program that runs in the background, what I need to know for debugging purposing is that I need to see what calls it is send and receiving for serial, network and to stdout. I know ...
1
vote
1answer
23 views

bash: history -a not writing unless HISTFILE already has text

Problem statement I've been following numerous examples for doing creative things with bash history along the lines of: # simplified example PROMPT_COMMAND='history -a; history -c; history -r' ... ...
-1
votes
2answers
32 views

How do I get a bash script to echo itself into a new file? [closed]

I have a bash script. I want to have this script recreate itself in /usr/local/bin without needing an additional file to do this. bash_a.sh: ssh -t -t server-a.com " cd /var/ irb ..etc " I was ...
0
votes
1answer
23 views

Double SSH and execute interactive shell

I need a bash script to ssh into server a then server b then execute an interactive shell. This is what I have: ssh -t -t server-a.com exec "ssh -t -t server-b.com <<<EOF cd ...
2
votes
3answers
233 views

xargs substition of more than one argument

By default xargs will concatenate many lines of its input and pass then to the specified command. For example: echo -e 'line 1\nline 2\nline 3' | xargs echo results in line 1 line 2 line 3 ...
0
votes
1answer
24 views

Why does this bash file stop my tomcat if the session closes?

The following bash script starts an Apache Tomcat and tails the log file to the screen: #!/bin/bash ~/tomcats/TC1_8083/bin/startup.sh tail -f ~/tomcats/TC1_8083/logs/catalina.out If I CTRL-C the ...
0
votes
1answer
26 views

What is the best / common practice to include a function that is used from several scripts?

I currently did this by sourcing a functions file including all my functions into the several scripts that use it: source ./functions.sh One disadvantage I noticed is that the line number bash ...
0
votes
2answers
47 views

java: command not found in cygwin bash

I'm trying to run a series of programs in Cygwin. My current dilemma is running a java file. My input and the error is below. Gaius@Ellislab2015 ~/muTect-1.1.4-bin $ java -jar muTect-1.1.4.jar ...
1
vote
1answer
31 views

Remove invalid domain names with Sed

I'm having trouble writing a sed command do the following. I have a file that should only contain "valid" domain names. How I use with sed to remove any line that does not match an expression? The ...
0
votes
1answer
29 views

Cannot exit normally when ssh'ing using bash script

I have a script that ssh into a server and sets up an environment ssh -t -t dev.example.com <<EOF cd var/dev/ ...other commands... EOF But when I type exit in the terminal after the script ...
2
votes
2answers
4k views

Moving files and renaming when a file exists in destination folder

I used to do this with Hazel. I'd move everything from ~/Downloads/ to ~/Downloads/Archive/Pictures, ~/Downloads/Archive/Documents, ~/Downloads/Archive/Videos etc. based on the file extension, and ...
10
votes
2answers
3k views

Bash: Replace all occurrences of a word in the last command

Almost by mistake, I figured out you could do something like: $ cp foo.data bar1.data $ ^bar1^bar2 And that runs the same command with bar2.data instead of bar1.data. Now, how about if I have ...
0
votes
3answers
24 views

How can I get the permissions of a file in octal format?

... and how can I set them? Does this work for directories in the same way? What happens with sticky bit and that more "exotic" stuff?
10
votes
4answers
844 views

Pass text to program expecting a file

Related to a question I asked on Stack Overflow: Passing multiple lines of code to wsadmin.sh?. I have, as a string, a few lines of input that I need to feed into a command. The command, however, ...
0
votes
1answer
13 views

Weird result of initiating a variable with the output of 'git describe'

For some reason this assignment: OUT=$(git describe HEAD) prints to the stdout (for example): fatal: No names found, cannot describe anything. Is this a normal behavior? Why doesn't this happen with ...
1
vote
4answers
71 views

How to disable set -e for an individual command?

The set -e command makes a bash script fail immediately when any command returns an non-zero exit code. Is there an easy and elegant way to disable this behaviour for an individual command within a ...
1
vote
2answers
34 views

How can I find out the number of arguments that are actually passed to a bash function?

Given a bash function: function f1 { echo "The function f1 is being called with ??? argument(s)." } and two invocations: f1 arg1 f1 arg1 arg2 How can I get the number of arguments passed? ...
5
votes
3answers
16k views

What does ~ mean in a Linux shell?

I'm new to Linux and have been seeing this often. Could someone explain the concept here? ~/.somefilename What does the ~ (tilde) signify?
0
votes
0answers
34 views

Running 'su - user sh -c “~/.profile”' returns “No such file” error

I have a shell script running as root with the following command: ssh remotehost 'su - user sh -c "source /home/user/.profile; <command>"' I get the following output: bash: su - user sh -c ...
1
vote
1answer
42 views

redirection - why it doesn't work this way

I know there are 3 streams attached to a process when it is run namely the input, output and error stream. And redirection execution work from left to right. I intend to execute a command, redirect ...
0
votes
3answers
82 views

How to manually send an ARP request

I recently sniffed with Tcpdump a packet "ARP, Request who-has 192.168.2.3 tell 192.168.2.2, length 28". I would like to reproduce this message, and to send an ARP request from my laptop to any IP I ...
14
votes
6answers
8k views

How do I keep my bash history across sessions?

I am working on a x86 target running fedora 9. Whenever I reboot it, my history returns to some state, and I do not have commands I did in the sessions before the reboot. What I have to change to ...
0
votes
0answers
20 views

using FISH shell — set default folder for multiple tabs?

I'm using fish shell in OS X. Using the standard bash shell, you can open multiple tabs in Terminal, cd to a different directory in each, and then save the setup as a Window Group (via Window > ...
3
votes
2answers
100 views

How to change the default shell in Cygwin?

I am trying to change my default shell from bash to zsh in cygwin. The normal unix command chsh isn't available on cygwin The etc/passwd file it seems isn't used anymore in existing versions of ...
3
votes
0answers
17 views

GNU screen is slow exiting

I've set up my .bashrc to automatically screen -DRA (even though it's a local session). screen works fine, except that if I run exit from the last window or otherwise close it from the client itself, ...
16
votes
8answers
18k views

How to write a script that accepts input from a file or from stdin?

How can one write a script that accept input from either a filename argument or from stdin? for instance, you could use less this way. one can execute less filename and equivalently cat filename | ...
4
votes
3answers
419 views

messaging.sh: line 29: [: missing `]'

I don't know if this is a bad thing, or what it means. My script still seems to work fine, but should I fix it? #!/bin/sh #This script will send text and maybe images to other computers via ssh and ...
1
vote
1answer
15 views

chmod without modding other user perms

I want to chmod a file but I want to do it so it doesn't effect the other "user"/"groups" e.g. giving the root 0 before 741 chmod 0** [filename] after 041 or give the group a 7 before 741 chmod ...
0
votes
1answer
21 views

expr bash command returning 0 in substring evaluation

What I'm trying to do is read a line from a file, store it in a variable $line and extract all instances of (that is, angle brackets with only uppercase letters between them). What I'm trying is: ...
-1
votes
2answers
768 views

What does $@ mean as a bash script function parameter

What does $@ mean as a bash script function parameter? Example: function foo() { echo "$@" 1>&2; }
1
vote
1answer
29 views

How do I dynamically print explanations for the current options used in linux commands?

Is there a linux tool that upon for example when I run: ls -lrt will not only print the result but will also print ls - list files -l - show extended list -r - reverse -t - sort by time AND ONLY ...
1
vote
1answer
26 views

How to get notified when a specific file is deleted in Linux?

I'm looking for a way to monitor a file and trigger an event as soon the file was removed. Once it is removed I will replace/copy a new file and start the monitor again. E.g. watch ...
-1
votes
1answer
54 views

How to move files from recursive hidden folder to the parent folder on OS X

I have a music directory 5 level deep, each folder have music and image files and also a hidden sub folder named .unwanted, I want to move the hidden files from folders named .unwanted, up one level ...