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

3
votes
1answer
128 views

How do I append an item to an array in a pipeline? [duplicate]

This script should simply add a value to an array through a loop and then show all items of an array. #!/bin/bash data_file="$1" down=() counter=0 cat $data_file | while read line; do \ ...
1
vote
0answers
29 views

What exactly files whose names' prefix is “AT.postflight.” are needed for?

I am not sure if this question should be asked here, since I am on an OS X, but since I am using bash, and I am asking about the meaning and the purposes of some files. I am trying to understand why ...
18
votes
2answers
23k views

“su” with error “X11 connection rejected because of wrong authentication.”

As root, I'm connecting to a remote host to execute a command. Only "standarduser" has the appropriate id-file and correct .ssh/config, so I'm switching the user first: su standarduser -c 'ssh -x ...
-4
votes
2answers
45 views

Web Server Log Analyse

I have a web server log file I have to create a command-line pipeline to display the top ten most visited pages. I then have to embed it in a shell script. I'm completely new to Linux coding so how ...
2
votes
1answer
23 views

What affect does precedence have on background task execution?

The two examples I have are: echo hi & And: (echo hi &) The first will give me the process id as a return result (e.g. "[1] 5627"), where adding precedence operators removes this. What ...
4
votes
6answers
200 views

Append something to each list in a file

I have a file, lists.txt, that looks like this: // stuff at beginning of file var list1 = new Array(); i = 0; list1[i++] = 'a'; list1[i++] = 'b'; ... list1[i++] = 'z'; var list2 = new Array(); i = ...
4
votes
2answers
68 views

How to shutdown a list of servers, making sure the first one is off before shutting down the next?

I have a list of 17 servers in this format: 172.16.6.45 i-052463fs (test-mv1) 172.16.6.46 i-9e2263rf (test-mv2) I'd like a script that can ssh/login to each and every of these servers and ...
1
vote
2answers
40 views

(Bash) kill process according to the memory used

i make this script to close a process, but i can't compare a output awk (var1) with a integer. the problem is casting in bash? #!/bin/bash var1= free -m |awk 'NR == 2'| awk '{print $3}' var2= ps ...
1
vote
1answer
50 views

Prevent path autocompletion from using CDPATH in bash?

On my Mac, bash (version 3.2.53(1)) autocompletes command-line arguments using files only in the current directory. On a Linux machine at work, bash (version 4.1.2(1)) autocompletes command-line ...
0
votes
1answer
14 views

Delete files that are not linked from an html file

Given an html file, something like myfile.html, and a folder with some files in it that are part of the web-page and others that are not linked in the html. How can you delete the files that are not ...
3
votes
2answers
33 views

Function with many arguments but only one switch

I am effectively making a recycling bin via some scripts I made. The first script is pretty much an alternative to the rm command (instead of actually deleting a file, it moves it to a deleted ...
2
votes
1answer
90 views

Why root bash output is colored but `sudo ls` output is not?

In bash (Ubuntu) I get colored outputs either as root (after sudo su) or as a normal user. I checked (after reading this post) the files .bashrc for normal user and superuser and the options related ...
0
votes
1answer
55 views

Bash will not execute system command in Perl script

Need a Bash file to run a perl script. This is the Perl file. #!/usr/bin/perl -w use strict; system "fastacmd -s $Q -d $NewQuery -o ./gifiles/$Q.$NewQuery.txt"; I have left alot out to avoid ...
5
votes
3answers
589 views

For loop formatting

I am having trouble formatting nested for loops for long strings of input: I am currently using the below nested for loops to name output files from a separate program that I have omitted: ...
1
vote
1answer
317 views

grep (/sed/awk) month range

I've looked around for solutions to this, but it's sort of difficult to search for the solution to such a specific problem (lot of words to put in Google). So, I have a file with data that looks like ...
0
votes
0answers
28 views

Bash Completion hangs all inputs

When I try to bash complete in terminal my computer stops responding to inputs, although the mouse can still be moved. After a few seconds it picks back up and everything continues normally. I'm ...
3
votes
1answer
10 views

Linux init script what does 0<&- &> achieve

Sorry if this is the wrong medium to ask this question. I looking into writing my own init.d scripts to control several services running on my Linux server. I came across an example online which ...
-2
votes
1answer
25 views

Shell script curl limit the try time for page not found

I found following code to check web url. if curl --output /dev/null --silent --head --fail "$url"; then echo "URL exists: $url" else echo "URL does not exist: $url" fi Here if the page not ...
14
votes
3answers
6k views

Bash subshell creation with curly braces

According to this, placing a list of commands between curly braces causes the list to be executed in the current shell context. No subshell is created. Using ps to see this in action This is the ...
3
votes
2answers
132 views

Subtract floating numbers in shell script

I'm trying to do some calculation in shell script with CPU usage. Which return floating point number. But when I subtract this number I'm getting error. See the following code and error. Code ...
0
votes
1answer
34 views

Running script through bashrc causes nesting of tmux panes

I use the following tmux code in a script file tmux-dev.sh and add it to bash using bash /home/rohit/tmux-dev.sh : tmux new-session -d tmux split-window -h tmux split-window -v tmux -2 attach-session ...
38
votes
6answers
6k views

Is there a one-liner that allows me to create a directory and move into it at the same time?

I find myself repeating a lot of: mkdir longtitleproject cd longtitleproject Is there a way of doing it in one line without repeating the directory name? I'm on bash here.
3
votes
3answers
629 views

how to execute a bash command in a python script

How can I launch a bash command with multiple args (for example "sudo apt update") from a python script?
0
votes
0answers
27 views

How to get back my splitted screen after I lost connection with “screen”

I was executing the screen command with a splitted window in my CentOS server then I lost connection to it. I reconnected to my server and I did screen -r to get my screen back but now I don't see ...
20
votes
3answers
11k views

What color codes can I use in my PS1 prompt?

I used several colors in my PS1 prompt such as \033]01;31\] # pink \033]00m\] # white \033]01;36\] # bold green \033]02;36\] # green \033]01;34\] # blue \033]01;33\] # bold yellow Where can I ...
3
votes
1answer
29 views

How do you make an alias or function that retains tab completion?

I made an alias to save some keystrokes with working with systemd: $ alias sctl='systemctl' However, this breaks tab completion for the subcommands. Is it possible to alias a command without ...
3
votes
1answer
186 views

Shell script error (: not found [No such file or directory]) [duplicate]

I'm using following script on linux server. And which is giving: : not found [No such file or directory] This is the script: # ------------------------------------------------------------------ # ...
2
votes
3answers
46 views

Duplicate a file with random probability

I have a directly full of images and I am trying to put together a script/command that will randomly copy (with some probability) the image to a location with a random name at that destination ...
1
vote
1answer
46 views

error ./c.sh: line 24: [: too many arguments in shell program

I am trying to make a shell script to print the amount of time user was logged into the system but I encountered a too many arguments error. I tried many methods from the internet but none worked. ...
8
votes
2answers
21k views

bash shell - ssh remote script capture output and exit code?

I wish to use shell to invoke a script on a remote server. I would like to capture the output of that script (its logging messages) and the exit code it returns. If I do this: ssh user@server ...
1
vote
1answer
45 views

Reading input fields separated by spaces

How can I read in POSIX bash input like this: <name>,<tag1> <tag2> <tag3>… I tried while read line;do done but this wants newlines, all I have is spaces. (Is IFS solution? ...
2
votes
1answer
121 views

Why does bash parameter expansion not work inside systemd service files?

I am trying to use systemd's EnvironmentFile and add an option to the command when it is set in the file. I have the following in the unit file: ExecStart=/usr/bin/bash -c "echo ${PORT:+port is ...
2
votes
2answers
6k views

Convert csv to HTML table

I have a Medical.csv file with rows of following format, field: 'participation.type', displayName: 'program_type', type: 'String',path:'participation' field: 'participation.program', ...
4
votes
1answer
9k views

ctrl c vs. ctrl z with foreground job

Ctrl+Z stops the job whereas Ctrl+C kills the job. Why is that? Wouldn't the other way make more sense? z@z-lap:~$ sleep 100& [1] 4458 z@z-lap:~$ sleep 200& [2] 4459 z@z-lap:~$ jobs [1]- ...
10
votes
6answers
461 views

Remove lines from a file depending on lines found in another file

File file1.txt contains lines like: /api/purchase/<hash>/index.html For example: /api/purchase/12ab09f46/index.html File file2.csv contains lines like: <hash>,timestamp,ip_address ...
0
votes
1answer
28 views

echo or sed out of a ks-file to generate a mysql_secure script

i will create a KS File (Kickstart for automated OS installation). i install mariadb with the ks file. But it seems a problem to execute the mysql_secure script. My idea is to generate a script in ...
1
vote
1answer
45 views

How to use sed to replace keys in a file using a regex?

I would like to modify a file to replace keys, suppose these keys are in the file as: 42NM 52NM 23NO XNNM I would like to replace anything with NM, with the word "Okay". 1 #!bin/bash/ 2 3 if [ ...
0
votes
2answers
821 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 ...
0
votes
1answer
34 views

When I press tab for autocomplete in bash I get: “Cannot parse arguments: unknown option -r” [duplicate]

My tab key's autocomplete function is not working. Instead, it spits out this error message: Cannot parse arguments: unknown option -r
2
votes
2answers
40 views

Using reverse SSH tunneling in one step instead of two steps (with -X)

Suppose we have three hosts: miki - my computer behind a NAT vps0 - my VPS mum - computer of my mother, behind a different NAT. The task is to connect from my computer to my mum and keep X11 ...
0
votes
1answer
2k views

Changing title without changing prompt on Cygwin

I have the following shell script function from this site that allows me to change the title in both Putty and Cygwin. In Putty connected to a Linux host it changes the title and leaves the prompt as ...
0
votes
0answers
23 views

Continuum Anaconda Fedora 22 path

After an update to Windows 10 caused problems in my dual boot system I had to reinstall Fedora 22. So, starting with a fresh system I reinstalled my work environment. The one installation that has ...
0
votes
1answer
60 views

I can't change user's passwd on ubuntu

I want change 120 user's password. so I wrote sudo echo 'user:passwd' | chpasswd but I had a message, chpasswd: (user) pam_chauthtok() failed, error: Authentication token manipulation error chpaswd ...
4
votes
4answers
153 views

Null and escape characters

I know that a filename in Linux has no restriction whatsoever excpet for two characters '/' and '\0'. I know that '/' is prohibited because it is a directory separator but is there any other reason ? ...
1
vote
3answers
66 views

How to run an infinite loop in the background

How can I run an infinite loop in the background, while continuing on with the script's execution? Example "script": while true; do something_in_the_background; done ...
1
vote
3answers
58 views

Process text file - Extract data starting with number

I have a list of contact information I need to process in .txt format seperated by , . We only want to keep SIC codes that start with 65 which is real estate. The command should only check for the ...
0
votes
3answers
62 views

find command behaviour inside for loop

I have following part of code inside bash script. for dir in $(find /etc/aaa -type d -maxdepth 1) do #my code done #my code if /etc/aaa directory is not present then i want to exit script with ...
2
votes
3answers
64 views

Grab the last executed command from history as a string and store in variable in bash

I'm trying to grab the last executed command, with options, and store it as a string to be written to a file. I've tried using fc but that can only give me the next to last command (for me anyways) ...
6
votes
1answer
65 views

Bash: How to avoid variable name substitution when using auto-completion?

I'd like Bash to stop removing variable names from paths and replacing them by their values. I tried several 'shopts' settings in various bash versions but was not successful in keeping a variable ...
0
votes
0answers
32 views

Continuum Anaconda Fedora 22 Linux path

After an update to Windows 10 I encounter problems in my dual boot system so I had to re-install Fedora 22. So, starting with a fresh system I re-installed my work environment. The one installation ...