Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead.

learn more… | top users | synonyms

70
votes
4answers
21k views

What is the difference between “&&” and “;” when chaining commands

What is the difference between the following methods of chaining commands? cmd1; cmd2 cmd1 && cmd2
0
votes
0answers
14 views

Script to hard-link copy new files in a source directory? [duplicate]

I am using Emby's media auto-organize feature. This features takes a watch folder and moves the media to the appropriate directory. It's not perfect so sometimes it moves the media to the wrong ...
0
votes
0answers
13 views

searching through command line history [duplicate]

I use reverse search when looking for a particular command on the command line by pressing CTRL + R. That returns the first command it finds in reverse order. To go back to the next further command I ...
0
votes
3answers
52 views

Perform parameter expansion before brace expansion? [duplicate]

Bash manual says that brace expansion is performed before any other expansions. I am writing a script which accepts two arguments: #! /bin/bash for b in {$1..$2}; do echo $b; done I run it like: ...
4
votes
5answers
423 views

Can I display GIT in prompt when current directory has a .git folder?

Can I display GIT in prompt when current directory has/contains a .git folder? Is there a way to do this? My current prompt is defined like so: export PS1="[\u@\h] \w $ " So, my prompt looks ...
3
votes
1answer
35 views

integer expression expected

I have the following script that is trying to match and IP address with a value in a file #!/usr/bin/env bash #To find the IP via ping ping=$(ping federicolivieri.noip.me -c 1) #To cut the result ...
1
vote
7answers
483 views

Matching n letter filename with ls

I am using the ls command in bash, trying to find all files or directory of length n. Let's say n=5 My command is: ls ????? But this would also include characters that are non letters such as ...
-7
votes
0answers
38 views

what does “-rwxr-xr-x 1 root root 920788 Mar 28 2013 bash” mean? [duplicate]

I am doing a school assignment, I am struggling abit because I am not a frequent mint user. Could someone please explain to me in detail what this means. -rwxr-xr-x 1 root root 920788 Mar 28 2013 ...
1
vote
1answer
24 views

Debian : Setting path for Node with root accessible globally

I have downloaded NodeJS setup and have it inside at /home/deploy/nodejs. I am trying to set its path, but it's not working out. I am logged in as root, and I would like to access nodejs and npm ...
14
votes
5answers
26k views

Script to change current directory (cd, pwd)

I want to run a script to simply change the current working directory: #!/bin/bash cd web/www/project But, after I run it, the current pwd remains unchanged! How can I do that?
1
vote
2answers
25 views

Is it possible to start tmux visible session

The code below will run source ~/.bashrc under tmux but this will not open tmux on the terminal. #!/bin/bash tmux new-session -d -s my_session 'source ~/.bashrc' I want the below effect from the ...
0
votes
2answers
2k views

VLC script on ubuntu server

I need a small script which run three vlc command on the same time (on Ubuntu server 14.04) as stated below: #!/bin/sh cvlc -vvv v1 --sout ...
-1
votes
2answers
41 views

How to convert a string into a date in a given format

Need a string in '9-2-1832' format in a '1832-09-02' format. Must be able to fill a 'date' type field in mysql.
3
votes
1answer
48 views

Why does bash 4.3 keep allocating memory in a script

Why does this shell script gradually consume more memory in bash? I’m not using any local variables and although the value of cpid is changing at every iteration because ls exits immediately, but it ...
2
votes
2answers
36 views

Switch user to root and run execute the rest of the script

I need help in changing the user to root and run the rest of the commands as root in shell script. Please help me do that.
2
votes
1answer
501 views

How to use history commands with readonly PROMPT_COMMAND?

I'm sometimes logged in on a host which I do not control and where PROMPT_COMMAND is readonly. Is there some way to work around this to run history commands anyway, for example using PS1? I've tried ...
-1
votes
2answers
44 views

shell script replace and add next line with special characters [closed]

I am trying replace a line with another line and add new line below that using a shell script. I want to replace: export PATH with: ...
0
votes
2answers
139 views

Daemonize a process in shell?

http://linuxg.net/how-to-transform-a-process-into-a-daemon-in-linux-unix/ gives an example of daemonizing a process in bash: $ nohup firefox& &> /dev/null If I am corrrect, the command ...
1
vote
4answers
41 views

Bash file - find value from command output and keep as variable

I am trying to make a script that will conntect to a ups and get the battery value and store it in a variable. I have managed to connect to the ups and get infomation from it but I am strugling to ...
0
votes
1answer
46 views

Parse xml returned from curl within a bash script

I've been digging through stackexchange for the past few days and I've found bits and pieces of what I'm trying to accomplish, but I'm unsure how to put it all together... I'm trying to create a ...
1
vote
2answers
35 views

Get full directory of $file

My first shell script #!/bin/bash echo "Input your file" read $file path=(readlink -f $file) echo "$USER, $path" >> scriptlog.txt it said missing operand. How can I fix it?
0
votes
1answer
36 views

how to compress all folders in a directory

I have a directory full of folders and I was wondering if there is any command to compress all the folders in a directory X with date in the name of the file and not update old ones in case they ...
1
vote
2answers
154 views

'hhighlighter' wrapper script saying command not found

I have gotten the wrapper script 'hhighlighter' from https://github.com/paoloantinori/hhighlighter which colors anything you want in stdout. I followed the instructions about installing ack-grep, ...
0
votes
1answer
832 views

Run supervisord without root access

Hi I'm really new to writing scripts and I searched a lot but all that I've found is scripts with full access. I don't have access to the /etc. I'm working in a host in the cloud but I have limited ...
49
votes
2answers
36k views

Awesome symbols and characters in a bash prompt

I just ran across a screenshot of someone's terminal: Is there a list of all of the characters which can be used in a Bash prompt, or can someone get me the character for the star and the right ...
1
vote
0answers
37 views

What does the `$>$` mean in the command `badblocks /dev/fd0H1440 1440 $>$`? [closed]

In the book 'Linux System Administrator's Guide' in website Linux System Administrator's Guide, the command badblocks /dev/fd0H1440 1440 $>$ is in section 5.10.4. Creating a filesystem, so what ...
67
votes
4answers
8k views

Is there a “.bashrc” equivalent file read by all shells?

Is ~/.bashrc the only place to specify user specific environment variables, aliases, modifications to PATH variable, etc? I ask because it seems that ~/.bashrc seems to be bash-only, but other ...
0
votes
2answers
45 views

backspace doesn't work when running c++ program

Whenever I use ./a.out to run a c/c++ program in bash, I cannot backspace when entering input. Instead I got a box with a question mark.
0
votes
1answer
56 views

associative array with two strings

is it possible to loop a simple array with key and value with a string in the [key] part ? #!/bin/bash -x wget url://stringlist1 wget url://stringlist2 #cat/sed some stuff .... declare -A ...
3
votes
2answers
71 views

Why does ls .* show different files than ls ./.*?

Blank file .ignoramus in current directory exists. bojan@localhost:~$ echo $GLOBIGNORE .ignoramus bojan@localhost:~$ ls .* | grep ignor bojan@localhost:~$ ls ./.* | grep ignor ./.ignoramus tools ...
2
votes
2answers
57 views

bash read of a newline, printf reports character 0

I use bash printf function to print ASCII codes of characters in an input file, but for some reason printf outputs ascii code 0 for LF characters, instead of 10. Any ideas why? while IFS= read -r -n1 ...
0
votes
1answer
25 views

Source ~/.bashrc when using the shell recorder `script`

I am using the first answer from How to automatically record all your terminal sessions with script utility to record my terminal sessions, however, I can not figure out how to get my bashrc to be ...
2
votes
1answer
61 views

Multi processing / Multi threading in BASH

I have a test file that looks like this 5002 2014-11-24 12:59:37.112 2014-11-24 12:59:37.112 0.000 UDP ...... 23.234.22.106 48104 101 0 0 8.8.8.8 53 68.0 1.0 1 0.0 0 68 0 48 Each line contains a ...
1
vote
2answers
30 views

How to color some strings in a file

I prepare a file Hello.txt as follows. 1253125213 213532135 23513125215 Then, I want to color each line blue except "2", and color the "2" red. At first, I wrote BLUE='\033[0;34m' ...
4
votes
5answers
61 views

execute command on a defined range of directories

Is it possible to 'partition' a directory listing - say in to blocks of some number, to perform different actions on each 'range'? For example, lets say I have the following directories inside ...
-4
votes
2answers
47 views

syntax error near unexpected token 'else' and possible incorrect indentations help needed

I'm trying to write a shell script which creates a user then ask the user which group name the user wants to assign the user which they have just created to and at the end it needs to ask if the user ...
1
vote
3answers
2k views

Split XML file into multiple files

I have an xml file that have different nodes, I want to split files like this: <unix> <mm> </unix> <osx> <nn> </osx> When I run the script I want it to make ...
-5
votes
1answer
49 views

help with a bash shell script that creates directories

I have a problem I been trying to tackle. If anyone can help, it would save me a headache! For reference,I started self learning so I'll be looking for problems around but can't find the answer for ...
1
vote
1answer
25 views

Compare and merge config file in CentOS

I was trying to setup an auto-update (for multiple servers) bash script via cron to a config file (text based) by downloading the new file everyday and replacing it directly. The script works fine, ...
0
votes
1answer
56 views

Why “lsof” is not working when it used in ssh? [duplicate]

I found this command line is not working ssh i01n10 "/usr/sbin/lsof -p $(pgrep -nf a.out)" it shows the error lsof: no process ID specified However ssh i01n10 "$(pgrep -nf a.out)" ...
0
votes
2answers
23 views

Why does ls still show the file excluded via GLOBIGNORE?

File missing with echo but present with ls -a. Why? bojan@hyperion:~$ touch .ignoramus bojan@localhost:~$ ls -al | grep ignor -rw-rw-r-- 1 bojan bojan 0 Apr 19 19:05 .ignoramus ...
0
votes
3answers
71 views

How to tell if a command executed by `exec` runs successfully or not?

When running a command with exec, the parent shell will exit upon the command finishes running. How can I tell if a command executed by exec runs successfully or not?
-4
votes
1answer
48 views

Is the value of a variable lost after a command is executed?

There is a functional difference between using: n=$1 shift And using: n=$1; shift in bash and zsh: the value of n is lost after the shift is executed in the first example. But both have the ...
3
votes
4answers
133 views

Check if a shell variable has more than one line using built-ins?

I can do this by calling the external utility sed (for a known non-empty $myvar) like so: if [ "$(printf %s "$myvar" | sed -n '$=')" -eq 1 ]; then echo "Your variable has only one line, proceeding" ...
2
votes
1answer
22 views

Connect via telnet and doing certain operations

I'm trying to code a script where I can connect via telnet to another server and execute certain operations, but I'm having problems with the result of this process. The objective is to connect to a ...
1
vote
2answers
39 views

Using awk to combine two csv files on three fields too create a new csv file

I would like to compare fields in 2 csv file and create new csv file for output. I have 2 csv files; this first file is PCs in my network: ...
0
votes
1answer
25 views

How to Wget with Subset Condition?

I want to download a subset of data recursively in the website that is within HTML class .container current main page in .container daughter pages of links also in .containers in daughter pages ...
6
votes
2answers
8k views

export HTTP_PROXY and special characters in passwd

Suppose for the sake of argument my password below is abc123@ I need to authenticate my linux machine through a corporate proxy to get patches and updates... normally I'd use this: export ...
1
vote
1answer
23 views

Triggering an event based on output of a second command

I'm scripting a deploy to cloud foundry using the CF CLI, and would like to capture the logs related to the new application being started up for analysis. This requires two different commands ...
1
vote
0answers
26 views

Forward stdout to different tty

I have an external device, that I can send commands to, and it would respond in a certain way. For this I use two terminals, one sending the commands and one listening to the response. At some point I ...