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

-2
votes
3answers
102 views

Why the builtin `test` fail with 'less than' (<) and 'greater than' (>)?

This code: #!/bin/bash if [ "4" = "a" ]; then echo "equal"; fi if [ "4" > "a" ]; then echo "yes 1"; fi if [ "4" < "a" ]; then echo "yes 2"; fi echo "exit" prints this three lines: yes 1 yes ...
0
votes
1answer
17 views

Run for loop with sections of different behavior

For example: I have 100 folder names saved in a text file, how can I apply different command line in the same for loop for every 10 names? In other words If I want to rename every 10 folders with a ...
2
votes
2answers
28 views

Can I ignore __pycache__ directories in bash-completion and grep?

I've ignored __pycache__ in my git repos and in vi's wildmenu. The last place these directories pollute my workflow is when recursively grepping through project files and when using tab ...
1
vote
2answers
57 views

Odd syntax for ssh and bash to run command

I'm pretty new to shell/bash scripting and I'm writing a script on OSX to automate some rather tedious efforts. I'm trying to run a portion of my script on a remote host using ssh. There's a common ...
2
votes
1answer
42 views

Bash do action as nobody and nogroup?

I have a log file that was created by nobody:nogroup, which is activity being logged to, I wanted to emulate adding a message to that log file. My first though was to: $ sudo su nobody This account ...
1
vote
2answers
25 views

Bash not sourcing ~/.bash_profile on os x

I just got this really wierd poblem. When I start bash, I get these two lines: -bash: fasd: kommandot finns inte -bash: brew: kommandot finns inte "kommandot finns inte" means command does not ...
0
votes
2answers
55 views

Transform row of integer into multi-column output

I am trying to get the input of a file to generate me a list with rows and columns of that numbers in sorted order. This will be use to generate a printable document later, so i am able to replace the ...
1
vote
2answers
65 views

How tp Print/echo arrow key in unix - bash, version 3.2.52

How do I print ↑ and ↓ in Unix? Basically I have a script written in bash and I am printing some numbers with whom I want to print arrow keys to show increase/decrease. So how do I literally print ...
0
votes
2answers
110 views

What is the alternative for ls command in linux? [duplicate]

How can I list the current directory or any directory path contents without using ls command? Can we do it using echo command?
1
vote
4answers
63 views

bash dynamic (variable) variable names

I want to dynamically create a sequence of strings by manipulate an array of elements and create some arithmetic procedure. for name in FIRST SECOND THIRD FOURTH FIFTH; do $name = $(( $6 + 1 )) ...
5
votes
2answers
45 views

Bash wrapper that will format the output of another program

Is there a wrapper or a method to force the output of another program (let's say 7zip) inside a bash script to be formatted in a given way, say, coloured or indented? Or even run in a separate small ...
-1
votes
2answers
34 views

Loop over columns and store values to associative arrays

I've got a text file containing two columns, like so: 26 0.000342231 27 0.000342231 28 0.000684463 29 0.00136893 30 0.00102669 31 0.00308008 32 0.00308008 33 0.00444901 34 0.00718686 35 0.00718686 36 ...
0
votes
0answers
29 views

Writing a basic shell script [duplicate]

I'm using a cluster and I want to write a start up script to run the commands I have to run at the beginning of every session. My script looks like this #!/bin/sh module add apps/COPASI module add ...
3
votes
1answer
41 views

What is the effect of the underscore in [A-Z] [_a-zA-Z0-9]*?

In regards to regular-expressions what is the effect of the underscore in [A-Z][_a-zA-Z0-9]*
6
votes
3answers
622 views

Insert empty line between command line prompts

When using the command line, often it gets very cluttered. Making it inconvenient to examine past commands and their outputs for example. I would like to have a newline added each time before the ...
0
votes
0answers
32 views

find on bash script ignoring foldes with brackets [duplicate]

Strange issue here using bash, in the following script (this is a simplified version) the find command should bring all folders but it ignores some folders: /Home Made videos /Home made videos ...
1
vote
1answer
62 views

How to execute a for loop in bash as a string

I need to execute a loop as a string. This: bash -c "for l in $(/bin/ls /dir1); do /bin/ln -sf $l /dir2/; done" Gives an error: /bin/bash: -c: line 1: syntax error near unexpected token `file1' ...
0
votes
1answer
56 views

How to use pipe to assign a variable [duplicate]

I am new to bash script. Probably this is very easy but for me it's not working. How can I assign value of $x1+$x2 to bc by piping. here in my code $bc holds no value. echo -n 'value x1 : ' read x1 ...
-1
votes
1answer
90 views

Argument list too long with just 5000 files [duplicate]

I have a folder with 5000 files that I want to copy somewhere else. When I do cp ../folder* ., I get the following error: -bash: /bin/cp: Argument list too long However, getconf ARG_MAX returns ...
0
votes
0answers
28 views

vim no tab completion in bash

When in shell, running vim <anything> and pressing tab, doesn't auto complete or show the list of the available files. Although it auto completes for the directory names, but not the file names. ...
0
votes
1answer
31 views

How to make OpenVPN to autoreconnect to gateway at any time

I've recently discovered a built-in way to have OpenVPN to auto connect to VPN gateway on startup, which is via setting profiles .conf files in /etc/default/openvpn as a part of AUTOSTART parameter. ...
3
votes
2answers
62 views

read only TMOUT variable – workaround to disable automatically exit shell when there is no activity

We have here a read only Bash variable. I am not allowed to unset that variable. $ echo $TMOUT 1800 As a workaround I wrote those lines (that my session don't exit) #!/usr/bin/perl $|++; while ...
-5
votes
0answers
49 views

Where buitin variables are stored in bash?

Where can I find the code of bash builtin variables? I have downloaded the bash source code but cant find it inside. Are they themselves a script or code written in C-language?
2
votes
1answer
45 views

What are the disadvantages of using config file (source) for passwords in bash scripts

I am writing a bash script that needs to authenticate a Linux box with active directory. I would like to make it so no user input is required. The problem is I have to put the password in the script, ...
3
votes
2answers
34 views

Create folders for specific items in table

I have data organized in a table (text tab delimited) as bellow: NAME TIME ID DATE -------- John 03:25:01 A10A 2015/05/12 Marry 01:01:15 N000M ...
4
votes
1answer
55 views

Recursively grouping symlinks by original file

Pardon me, but I don't actually know where to begin with this - I will update if I get further. Sorry. Basically, I've got a list in a text file similar in structure to the following: ...
0
votes
2answers
59 views

Loop through * files using $1 in bash script

I am writing a script to act on files given to the script using the $1 variable. What is the best way to loop through these files. At the moment I have hard coded the script using something like for ...
-1
votes
1answer
58 views

Why is bash confusing this HEREDOC limit string as a command?

I am trying to use nested HEREDOC blocks in a bash script. Note The outer HEREDOC is user to run a list of commands as a different user via sudo the inner HEREDOC is capturing regular text to cat ...
0
votes
1answer
21 views

Bash exit from subcommand [duplicate]

I have a script with the following code: command_that_could_fail || (echo "command failed"; exit 1) However, the exit seems to just be exiting from the sub-command formed by the second part of the ...
1
vote
0answers
20 views

How to quickly search and navigate to the particular sub directory? [duplicate]

I often find myself in the situation where the directory structure is like: a/b/c/d/f/g/... and I am at a as pwd and wish to quickly navigate to f or g. Is it possible to search and move to the ...
3
votes
3answers
92 views

Organize entries as a spreadsheet (csv) using awk

I have information for entries (N= 1000) saved on a computer in a delimited text file/per entry ( every entry has one text file). The information recorded in the same format as the following: ...
1
vote
2answers
39 views

A variable in Bash that contains quotation marks and spaces

I'm trying the following in a Bash script: MV_PARAMS='"foo 1" "foo 2"' mv $MV_PARAMS What I want to actually execute is: mv "foo 1" "foo 2" But it doesn't seem to work. trying this: mv ...
1
vote
1answer
52 views

Bash script with “execute” command and strange regexp

So I was looking through Paul Irish's dotfiles and found reference to this bash script: #!/bin/bash cd "$(dirname "$BASH_SOURCE")" \ && source 'utils.sh' declare -a FILES_TO_SYMLINK=( ...
4
votes
1answer
60 views

How could a script know the path of the .desktop file that launched it?

How would a bash script know if it has been launched by a .desktop file, and how would it know the path of that launcher? Extra Points: How would I extract the "comment" field of that .desktop file - ...
1
vote
1answer
38 views

nemo: Context Menu Action Triggering a Script that Forces the Selected Symbolic Link to be Relative

My goal is to be able to right-click a symbolic link in nemo, triggering a custom script that forces the link to be re-written as a relative path, should it happen to possess an absolute path upon the ...
1
vote
1answer
63 views

grep entries from delimited text file and include it in another command

I have database for persons and path to their files which stored on a computer. This data saved as (a very long) delimited text file as follows: ============ NAME: John TIME: 12:31:25 PATH: ./a/b/v/c ...
4
votes
5answers
190 views

Remove characters while naming files or folders

I have a text file with multiple rows. In every row I have the date in the following format: 12/2/2015 15/9/2013 08/3/2011 02/5/2005 . . . I want to create a folder for every line in this text file ...
3
votes
1answer
44 views

Bash test on successful subshell command returns false

I don't quite understand this behaviour of bash test operator. I used this line to determine if vagrant is installed. if [ $(vagrant --version > /dev/null) ]; then echo "HELLO"; fi I now know ...
0
votes
3answers
46 views

Splitting a pdf-file into 2 pdf's (one contining equal pages etc…) [duplicate]

I have a 600 pages long pdf file. I would love to be able to split it in different pdf files, one containing odd-numbered pages: 1,3,5,7,9,11 etc. and another file containing even-numbered pages: 2, ...
0
votes
1answer
16 views

Bind C-j to backward-kill-word, says command not found

bind -x '"\C-j": backward-kill-word' says, backward-kill-word: command not found As mikeserv quoted here, i am able to do backward-kill-word using Ctrl-w. However this is the same key i use in ...
2
votes
0answers
30 views

Restrict a user from viewing other user's processes [duplicate]

Suppose there are two users : user1 & user2. Now we know that if I give top -u user1, I can see only the process respective to user1. But if I do top -u user2, I can see all the process running ...
0
votes
2answers
27 views

Simple bash not running properly by cron

I created a small bash script that takes a file using wget and then processes it using a php. The code goes like this: wget -U mozilla -P /home/logfetcher/ http://fakesite.com/log.`date -d ...
1
vote
2answers
47 views

Store array to file and load array from file in BASH [closed]

I want to be able to store multiple integer arrays into a txt file when I'm done updating them, and then be able to load these arrays from the txt file into the script that I am using. The arrays ...
2
votes
4answers
168 views

How do I *reliably* and *simply* get the current shell interpreter name?

I'm looking for a simple and reliable way to get the name of the current shell from inside a script or a sourced file (not from the command line). I would have expected to just do $(basename ...
0
votes
2answers
60 views

Bash script arguments not being passed to function? [closed]

I'm trying to pass the arguments when invoking a bash script to a function defined in that script. In my head this is trivial but in practice seems more difficult. Script is: #!/bin/bash function ...
1
vote
2answers
62 views

Can bash shells automatically recognize Gnome terminal window's width?

/bin/less is the default pager on an Ubuntu 14.04.3 LTS desktop OS (the $PAGER variable is unset) and gnome-terminal 3.6.2-ubuntu1 is used. If I try for instance: $ man man The displayed output ...
1
vote
1answer
41 views

How can I hide the output of command line in terminal window?

Bellow is a simple code: #!/bin/bash -ef echo "Hello" > log.txt #saving the output of this command log.txt command1 #this command running and showing it is output in terminal command2 > log.txt ...
4
votes
2answers
93 views

How to tail a log file by time?

Say my log file(log.txt) is something like 2014-01-01 22:30:30 something happened.... 2014-01-01 22:30:31 something happened.... 2014-01-01 22:30:41 something happened.... I want to tail this file ...
0
votes
0answers
20 views

Multiple here documents in a bash script to drop in and out of sudo is causing error “Sessions still open, not unmounting”

I'm attempting to write a setup script that I can run on multiple machines to run a bunch of installers (requires sudo) but also do things like pull down a git repo (I want to run that as the normal ...
2
votes
4answers
165 views

How to take the absolute value using awk?

If I have below two dates: 2015-09-12,2015-08-13 And I need to get the number of days between them, I will use the below code: awk -F'[-,]' '{print 360*($4-$1)+30*($5-$2)+($6-$3)}' The output ...