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
2answers
44 views

Installation of latest version R for linux

First I typed sudo gedit /etc/apt/sources.list after that I got one sources list then I typed deb http://cran.rstudio.com/bin/linux/debian wheezy-cran3/ then I get the error like this No ...
-1
votes
1answer
28 views

sed throwing sed: -e expression #(number), char (number): unknown command: `(letter)'

I wrote a shell script which reads some files and copy all the data from these files to other consolidated file. This happens multiple times and previously copied data will not be copied again. For ...
1
vote
0answers
40 views

bash “no such file or directory” when sh symlink works! [closed]

I use tcsh on a Centos 6.5 64-bit system. I created a file x.sh with two lines: #!/bin/bash echo Yes yes That's it. Then did chmod +x x.sh. # ./x.sh /bin/bash: ./x.sh: No such file or directory ...
0
votes
1answer
40 views

Process substitution syntax. Forward/right bracket vs backward/left bracket

tldp lists two syntaxes for process substitution. >(command_list) and <(command_list) What is the difference, if any?
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 ...
2
votes
3answers
47 views

login shell (bash) - how to we invoke a login shell

I know what is a login shell and the difference between a login shell and a non-login shell. But what puzzles me is how it is invoked. It is said that a login shell is invoked with a - as argument ...
0
votes
1answer
59 views

Script with curl works manually but not in cron job

My script (status.sh) is: #!/bin/bash SITE=http://www.example.org/ STATUS=$(/usr/bin/curl -s -o /dev/null -I -w "%{http_code}" $SITE) if [ $STATUS -eq 200 ] then echo $STATUS >> ...
0
votes
2answers
34 views

Interactively remove files in loop with standard input redirection

I need to interactively (i.e. rm -i) remove files stored in variable $to_remove (one path per line). Unfortunately my code doesn't work because standard input is already used by redirection ...
0
votes
1answer
39 views

Count deleted files with interactive rm (rm -i)

I want to count number of interactively removed files and directories: for f in /tmp/mydir/* ; do rm -ir "$f" done How to do it in most concise/elegant way? Example: abc@def:/tmp/mydir$ tree ...
2
votes
1answer
59 views

SSH into a remote shell, execute a 'source' command, and stay in the remote shell

I've got a script, named s, on a remote server that activates a virtual environment like this: source venv/bin/activate When SSH-ed into the server, I'm able to activate the environment by . s ...
12
votes
2answers
593 views

Ask for a password in POSIX-compliant shell?

When I want to ask for a password in a bash script, I do that : read -s ...but when I run bash in POSIX mode, with sh, the option don't exists : $ read -s sh: 1: read: Illegal option -s How do I ...
3
votes
1answer
20 views

Proxify dns queries for bash command

I want to use different dns server (not tor, any dns server i set) for certain terminal command. Say it would looks like $ DNS_SERVER=8.8.8.8 dnsify ping example.com and it uses google dns. I know ...
3
votes
0answers
21 views

cursor and combining diacritics in shell

I frequently deal with combining diacritics, especially the combining acute accent (U0301, or \xcc\x81). I have a keyboard set up to insert this character, and that works fine in the shell. $ echo а́ ...
0
votes
1answer
68 views

Bash - check environment variables

The env command can be used to print environment variables in bash. I want to ask if there is any built-in command to do this ? $ export temp="hello world" $ env | grep temp The second command ...
2
votes
1answer
63 views

Bash - shell vs environment variable [duplicate]

I want to clarify a confusion I am having in shell variable vs environment variable. I did the following test, where I have a shell variable abc and export it to an environment variable. $ $ ...
1
vote
1answer
45 views

choose between one of two programs in bash script

I have a (bash) script I would like to run on two different computers, one is OpenBSD with the program sha256, the other is Ubuntu with sha256sum. What is the best/standard practice to allow the ...
1
vote
1answer
35 views

search and increase the values between the second tilde symbol and the 3rd tilde symbol in each line of a txt file

I was wondering is there any way to search and increase the values between the 2nd tilde symbol and the 3rd tilde symbol in each line of a txt file. Maybe vi can do this? For example, i have a ...
2
votes
2answers
98 views

Save list of echo outputs to .txt

I'm having a lot of trouble at work trying to save a long list of echo outputs as a .txt file on my desktop. I am using Bash in Yosemite 10.10.4. I am still very new to Bash so any help and tips are ...
0
votes
1answer
27 views

How to append extension to files with certain filename format

I have several files generated by a script but I neglected to have the script append a file extension. Each filename contains the substring k120 and no other file in the directory contains that ...
0
votes
1answer
57 views

What's wrong with this grep?

> output2.txt cd # some directory i'm trying to search find views/shared -type f -name "*.js" -print0 | while IFS= read -r -d $'\0' line; do echo -n "${line%.js}" | tee -a ...
1
vote
1answer
37 views

Prevent ssh-keyscan from generating output

Problem: When running ssh-keyscan in cron it emails me the output of ssh-keyscan every day. The email simply contains the following. # <hostname> SSH-2.0-OpenSSH_5.3 My (simplified) cron ...
1
vote
4answers
65 views

Bash Command Get Data from multiple files and append the file name

I have in a folder (eg /tmp) the following files 1.id 2.id 3.id 4.id so on... In these files, there is one number inside. For example in 1.id it can be the 1000, in 2.id it can be the 2000 etc. I ...
1
vote
1answer
43 views

linux how to cd to parent folder if navigated through a symlink [duplicate]

I have following symlink in my home directory. lrwxrwxrwx 1 mtk mtk 43 Aug 8 20:35 tripple-bit -> /media/mtk/study/Collage/docs I use the symlink to navigate to the docs folder directly. But ...
6
votes
4answers
70 views

How to repeat a command with an added parameter

I know how to repeat a command and add more text after it with !! like so: ls -l !! tmp The second line expands to ls -l tmp. But what if I wanted to add parameters to the command in between the ...
0
votes
1answer
36 views

.sh script error issues

I have a sh script with which I connect to postgres DB and execute a psql command. The script is as shown below: /opt/postgres/9.2/bin/psql pcwh -U pcwhuser << EOF \i ...
1
vote
2answers
41 views

join two file based on column when there is no one by one corespondness in bash script (awk, grep , sed)

file1.txt 112|9305|/inst.exe 112|9305|/lkj.exe 112|9305|/dje.jar 112|9305|/ind.pdf 112|9306|/ma.exe 112|9306|/ngg.pdf 112|9307|/jhhh.dat 112|9312|/ee.dat 112|9312|/qwq.dll file2.txt ...
1
vote
0answers
44 views

cd -P gives bash: dirs: +P: invalid number [closed]

When I attempt to cd -P with a symbolic link, I am getting this error: bash: dirs: +P: invalid number ~/.marks Wed Aug 12 - 02:48 PM > ls -la total 3 drwxrwxrwx+ 1 rbram Domain Users 0 Aug 12 ...
-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
27 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
55 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
24 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
63 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
103 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
59 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
31 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
619 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
56 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
55 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
26 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
56 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?