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
1answer
13 views

Avoid conversion to scientific notation in awk

I have a csv file that contains hundreds of columns. I would like to subtract the value of a specific column from a static number and then print the entire line. The values of that column are long ...
1
vote
5answers
108 views

How to get current working directory?

I want to have a script that takes the current working directory to a variable. The section that needs the directory is like this dir = pwd. It just prints pwd how do I get the current working ...
2
votes
2answers
21 views

Why is a variable passed to the su command, but not an array from the same scope?

In the example below, why does $var get passed to the su in the start function, but not the array modules ? #!/bin/bash var=cat modules=( one two three four ) start() { su gleventh -c "for i in ...
0
votes
1answer
21 views

Find and convert all ALAC files to mp3 / opus / aac

I'm looking for a way to convert all alac files in a directory recursively to another format. Problem: alac as well as aac use suffix m4a, so find -name "*.m4a" doesn't work.
0
votes
2answers
39 views

Why would the prompt get overwritten?

p_ash-3.2$ cp some_file1234.html /some/loc/ation/ofthe/some_file1234.html.html_Backu Have been seeing this intermittent issue with the command-line, while typing longer lines as part of any command, ...
1
vote
1answer
19 views

How to replace string of the file, which is present in tar file through UNIX

I have a tar archive xyz.tar containing lots of .sh files like: 123.sh 456.sh 789.sh Every .sh file has some string content, e.g. 123.sh contains welcome to Hollywood, 456.sh contains I love ...
0
votes
2answers
52 views

How do I move a line in a text file up or down by one line?

I have some text files, and I'd like to be able to move an arbitrary line in any of the files up or down one line (lines at the beginning or end of the file would stay where they are). I have some ...
1
vote
1answer
33 views

Copy files to a destination folder only if the files already exist. but the source files have a different file extension

Copy files to a destination folder only if the files already exist. but the source files have a different file extension. i.e I have a backup of some files with ".desktop.in" extension and I want to ...
1
vote
0answers
18 views

Running a script during booting/startup; initi.d vs @root

I am currently trying to understand the difference between init.d and @root for running a script at startup/booting of the system. The use of @root is some what simpler by simply going into crontab ...
0
votes
1answer
48 views

how to locate a name-not-specified file in bash? [on hold]

I have a bash like this to easily upload a file to my server: FILE=../"$1"/1.txt scp 1.txt remoteserver #upload the file to a remote server. The $1 is for input directory and I have a lot of ...
0
votes
0answers
52 views

What's the most efficient way to find out what is consuming disk space? [on hold]

I usually check disk space consumption by running du --max-depth=1 -h / but for some reason, it's taking a long time on one of my servers. What is the most efficient way of doing this?
-6
votes
0answers
30 views

Script for compare two file permissions

create dir, create two files with diff permission. Now write a script to test the permisiion of these two files. If its same then display the filename with its permission. if not display the ...
0
votes
1answer
20 views

Error with sed on MAC OS X invalid command u

Im french sorry in advance for my bad english... So i have an error on MAC OS X when im using sed sed -i '' '/user_pref("mail.identity.id1.reply_on_top", 1);/ a\ ...
1
vote
1answer
41 views

loop through multiple folders and perform commands then write to file

I have 10 folders that I want to loop through while executing the following command: awk 'FNR > 1' *.csv | sort -sk 1,2 | sort -sk 3,3 > ${f}_appended.dat With a for loop wrapper, like ...
1
vote
1answer
47 views

Shell script runs diffrently based on working directory.

I have a script which runs differently based on current working directory. Basically it processes an .ini file and takes parameters from it and runs mysql backup. Script is running as root user. ...
1
vote
1answer
42 views

cd to my folders shows me an error

I just logged out my system and logged on. And i tried to get into my folder cd /u/folder It says Too many levels of symbolic links. But it worked yesterday. What could be the reason? I found ...
2
votes
1answer
20 views

Running a constructed command from bash script

I constructed a command like this in a bash script a="my_cmd"; a="$a --verbose"; echo $a; $a; It works and executes my command correctly. But when I add an environment variable to the mix it ...
2
votes
1answer
38 views

Invoke subshell command with loaded rcfile

I have some Python code that does: (this is a simplified version) shell = os.environ['SHELL'] os.environ['PATH'] = ... # some new PATH value if call(shell, '-c', ...
1
vote
0answers
54 views

Source code of the patches for Shellshock

I have a project for my grad level OS class, and I have decided to choose the Shellshock vulnerability bugs as my topic. There is a lot of great information out there, but I was curious if it is ...
0
votes
3answers
29 views

Renaming multiple Files, Bash Script, preferably with an Addition

Hello you wonderful people, I have a little problem creating a Bash Script. I have 7000 image files (dicoms). These files belong together and should be in order in ONE directory. However, the program ...
0
votes
3answers
51 views

How to use password in shell scripting

I am writing a script which greps for for multiple files from 3 log files. One of the log file is created as superuser and every time it executes it prompts for password. How do I put it the same ...
0
votes
0answers
22 views

bash command to simply print new bash commandline like [tom@cerulean ~]$ [on hold]

My shell script used carriage return '\r' to erase my current [tom@cerulean ~]$ bash line to print an information (that is run asynchronously then returned when done). I want something that will to ...
0
votes
1answer
19 views

cron: output of a script?

I've got a cronjob that looks like this 0 0 * * 7 [ $(date +\%d) -le 07 ] && /home/archiver/archiver.sh &> /home/archiver/output And it works from the cron+bash perspective in that ...
1
vote
1answer
39 views

When did bash quit exporting SHELL?

I upgraded a Debian box from stable to Jessie and I noticed that SHELL is no longer exported, so screen and similar programs start dash for subshells instead of bash. When was this change made and ...
2
votes
2answers
51 views

How do I swap the two last command line arguments?

$ ln -s ./dir/target.txt /path/to/source.txt{cursor here} How do swap file typed filenames in command line? Alt+T swaps words, not filenames, resulting in ln -s ./dir/target.txt /path/to/txt.source. ...
8
votes
4answers
618 views

Spaces next to pipes

I've seen history | grep blah and history |grep blah; and history|grep blah also works, though no one ever seems to use it. Is there any significance in the spaces (e.g. piping to/from different ...
0
votes
2answers
25 views

use backquotes in a script [on hold]

Why this difference between echo $Date and echo "$(date +%s_%kh%M_le_%a_%d_%b_%Y)"? beginning=$(date +%s) diff="0" rest="$1" tmp="0" now="0" Date=`date +%s_%kh%M_le_%a_%d_%b_%Y` echo -n "$1" while [ ...
0
votes
2answers
41 views

Gzip file but excluding some directories|files and also append current date

I'm looking for a way to create a .tar.gz file from a directory but I have some doubts. I'm know that the command for create the file is: tar -zcvf /path/to/compressed/file.tar.gz /path/to/compress ...
3
votes
1answer
51 views

How to swap two commands in bash?

Say I have command A and command B but I want B to run when I type A and vice versa. I've tried alias A='B' alias B='A' But this doesn't seem to work for some reason. How do I do this? EDIT: ...
3
votes
1answer
25 views

How to sort an associative array and retain the keys?

I have an array with filenames as keys and a numerical value as values. MYARRAY[00001.jpg] = 31 MYARRAY[00002.jpg] = 200 MYARRAY[00003.jpg] = 98 I need to sort them so they are ordered by value. ...
1
vote
0answers
38 views

Bash cannot see PATH update

I am running Debian on a VM. I login to the GUI and go to Applications > Accessories > Terminal. # echo shell: /bin/bash I modified ENV_SUPATH, ENV_PATH inside of /etc/login.defs. I restarted ...
1
vote
2answers
25 views

Does X mangle prompt environment variables?

I'm starting it with startx. Before that I have PS1 in my environment: $ cat /proc/self/environ | tr '\0' '\n' | egrep '^PS' PS1=[\u@\H \w] PS3=> PS2=> PS4=+ From inside X I get: $ cat ...
1
vote
1answer
24 views

Why did a recent Ubuntu 14.04 update mess up my PS1 prompt?

I recently updated my Ubuntu 14.04 using the software update. This caused some problems. Initially I couldn't open up a new terminal window due to unknown errors with my .bashrc I had to use ...
0
votes
2answers
26 views

When is /etc/bash.bashrc invoked?

What is this file anyway? Documentation makes no mention of it. And it's not supposed to be run automatically (version 4.3, 2 February 2014): Invoked as an interactive login shell, or with --login ...
3
votes
1answer
39 views

How to append MD5 checksum of email content in bash?

I found some lines of output missing from an auto-generated email notification that was dispatched via cron. Having confirmed that there is no AVC error, I want to find out if the integrity of my ...
3
votes
3answers
89 views

spawn - command not found!

I am using Mac OS X 10.9.4, following is my script to copy files from local machine to different host #!/bin/bash #!/usr/bin/expect echo "I will fail if you give junk values!!" echo " " echo "Enter ...
2
votes
1answer
57 views

Test if postfix is running

I'm searching for a reliable way to test if postfix is running from inside a bash script. My first attempt was simply trying pidof postfix, which doesn't work. Then I tried to get the postfix ...
0
votes
0answers
5 views

Generating a .img from tarball: The /dev/loop devices [duplicate]

I'm trying to make a .img from a tarball using the following script: #!/bin/bash # Packages required # dosfstools parted # Can be run on any Linux system # loop.max_part=15 must be in kernel ...
1
vote
1answer
82 views

Swap two files in bash [duplicate]

How do I swap two files in Linux console with minimum typing? Boring approach: $ mv file1.dat fileX.dat $ mv file2.dat file1.dat $ mv fileX.dat file2.dat
4
votes
2answers
69 views

Use lines in a file to produce string and file name

I have a file, foo.txt, that has a folder name on each line: folder_1 folder_2 folder_3 And I'd like to do something like this: cat foo.txt | xargs -I {} echo 'function {}() { return stuff; }' ...
0
votes
1answer
32 views

How does `ls` know whether it's piped or printed [duplicate]

ls normally prints like this: 1 1249 1653 23 33 4581 6202 6447 789 836 903 config.gz kpageflags sysrq-trigger 10 1253 1658 24 34 4582 6206 648 79 837 ...
0
votes
1answer
37 views

Why does the input to xargs is 1 string but without is strings in separate line?

I am trying to pipe file to rm via xargs. I understand that what I am tryng to do could be done by git clean but I am practicing the cli. I tried this: for files in $(git status --porcelain| sed ...
0
votes
1answer
17 views

Values from two lists are not processing correctly within two nested loops

I am trying to pass some values contained in two lists to a simple echo within two nested for loops (the echo is used to look at what is generated inside the inner loop). But the results are not ...
2
votes
3answers
64 views

How do I use inserted values using getopts

I have this bash code combined with getopts and if I understood getopts correctly OPTIND contains the index of the next command line option and all the command line options provided to shell script ...
-1
votes
1answer
24 views

using the sed command in bash show output in a new text file? [closed]

Hey everyone I am new to the world of UNIX/Linux.My professor wants my class to use sed command to display output in a new text file but did not give us the commands; any help would be useful thanks
0
votes
0answers
18 views

Using a custom script for cron jobs mail notification

After coming across Mailgun I would like to write my own script to use their API in order to send mail notifications from cron jobs — avoiding in this manner having to worry about installing a ...
1
vote
3answers
56 views

Traverse all subdirectories in and do something in Unix shell script

I am new to bash scripting. I am working on a shell script and got stuck from last 3 days. I want my shell script to visit all subdirectories in a main directory. Do something in directories, sent ...
0
votes
0answers
30 views

Unrecoginzed option: using 'getopt' cmd in shell script [on hold]

What is wrong in the command: if ! options=$(getopt -n myscript -l a:,b:,cc:,dd:,ee:,ff:,gg:,hh: -- "$@"); then exit 1; fi I get an error msg: mhagent: unrecognized option '--hh' options=' --aa ...
1
vote
1answer
28 views

if command in find -exec

I was just trying to list all directories and files under current directory and also write if they are file or directory with the following command: find -exec echo `echo {} : ;if [ -f {} ]; then ...
1
vote
2answers
44 views

Extracting numbers with a decimal point from ls output in Bash

I would like to extract the numeric part of the file names that begin with "hsli" and end with ".h5" in Bash on Ubuntu 14.04.1 64-bit LTS. My ls -l hsli* output is as follows: -rwxrwxrwx 1 ongun ...