The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …).

learn more… | top users | synonyms (1)

1
vote
4answers
52 views

Dynamically reference a file's name

In a single directory, I'd like to replace the first line of each file with the file's name. Each file has as the first line "TestRelation." I'd like to replace it with the file's name. I know I can ...
1
vote
3answers
89 views

How to pass an array to a function as an actual parameter rather than a global variable

Is there a way to pass an array to a function as one of its parameters? Currently I have #!/bin/bash highest_3 () { number_under_test=(${array[@]}) max_of_3=0 for ((i = 0; ...
3
votes
3answers
138 views

How to rsync files between two remotes?

I would like to transfer files between two remote hosts using on local shell, but it seems rsync doesn't support synchronisation if two remotes are specified as follow: $ rsync -vuar host1:/var/www ...
0
votes
1answer
19 views

What is the meaning of “${name##*/}” in Shell [duplicate]

I have a code as while read name; do uuencode "$name" "${name##*/}"; done but I do not understand what is meaning of ##*/ in "${name##*/}" Google doesn't give good results. Can someone please ...
1
vote
1answer
31 views

Can .bash_profile be auto sourced after change?

I'm always wondering if there's a way to do this. I don't want to type source after changing my .bash_profile all the time.
0
votes
0answers
22 views

what is the meaning of “${x%*.*}” in shell? [duplicate]

While I am using the code as ${x%*.*} it is excluding the extension of the file. for e.g. $ x="file.txt" $ y="file.20150208.dat" $ echo "${x%\*.\*} ${y%\*.\*}" file file.20150208 But how this ...
35
votes
11answers
14k views

How do I reuse the last output from the command line?

This is a noob question, but I'd like to know how to reuse the last output from the console, ie: pv-3:method Xavier$ python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" ...
6
votes
3answers
6k views

How do I insert a space every four characters in a long line?

I've got a long line that I want to insert a space every 4 characters, on a single lone line of solid text to make it easier to read, what's the simplest way to do this? also I should be able to input ...
4
votes
3answers
82 views

Bash, insert last used argument of current command

I'm aware that you can recall the last argument of the previous command with !$ and also cycle through previous arguments with ALT + . but can you recall the last argument used for the current command ...
0
votes
1answer
30 views

Error while executing a.out from C shell

I am in my home directory. And there is an executable a.out in there. I want to execute it like- /bin/csh ~/a.out ^F^E@@@@@▒^A▒^A^H^C^D^B^B@^B@^\^\^A^A^E@@: Event not found. Its not that I cannot ...
0
votes
5answers
60 views

sed to replace with backspace

I have trail.txt, which contains spice netlist. Now I want to replace all expanded parameters to one line only i.e. remove + and append that line to previous line. trail.txt data + net06706 ...
0
votes
4answers
32 views

adding programs to path [duplicate]

I have a load of tools that are kept in the /opt directory. The tools are organised like this: /opt/toolname/tool.sh. My question is, how can I add the tools in my /opt folder to my path, so i can run ...
4
votes
4answers
1k views

Get vertical cursor position

This might sound pretty weird, but I know how to set the vertical cursor position in Bash like this: echo -e "\e[12H" This moves the cursor to the 12th line (starting with 1). So how do I get the ...
4
votes
9answers
728 views

Metaphor for the concept of shell?

I'm finding myself helping out some classmates in my computer science class, because I have prior development experience, and I'm having a hard time explaining certain things like the shell. What's a ...
3
votes
2answers
57 views

Loop over files returned from find?

I'm trying to piece together a script that recursively finds all the *.plist files in a directory and then operates on them. The script is below, but its producing unexpected results. The expected ...
1
vote
2answers
3k views

How do I sort using the grep and sort commands?

I would like to create a sorted list of all TCP services found in the file /etc/services, pipe the output of the command grep tcp /etc/services into the command sort, then redirect the output of this ...
0
votes
1answer
28 views

Running a “scheduled”/delayed script as sudo on server, via ssh - and right before ssh exit

This would have probably been answered by Keep running a script via ssh, if I didn't have to run a command as superuser. Let me try with an example: say on my server, I have this script as ...
1
vote
3answers
54 views

Shell script to find and count total number of characters in all the files

How can I make a script that finds every file in your home directory that is less than 3 days old and then gets a count of the total number of characters in all of these files?
0
votes
1answer
23 views

Can I treat all what I typed after a command as raw string?

I made a bash func for myself so I can through some words into a tree_hole file, it looks like this in bashrc: function th { echo -e "\n$@" >> /Users/zen1/zen/pythonstudy/tree_hole; } export -f ...
0
votes
1answer
62 views

How to know, when a shell command running in the backround getting killed or died

I am running a shell command which is invoking an avconv session. The command is running as a background process. When the script starts executing I am doing a curl post to a url with the created ...
1
vote
1answer
99 views

Set up graphic interface (desktop) for remote connection

I was assigned a CentOS VM that I manipulate through Putty. Everything I do to it is by command line so far, and I have admin rights to it. The VM is stored in the corporate data center served up by ...
7
votes
2answers
262 views

How do redirection in a symbols work in a sequence?

I have file1, file2, file3. file1 contains 1 file2 contains 2 file3 contains 3 I use command cat file1 > file2 > file3 Results in: file1 1 file2 (contains nothing) file3 1 Why ...
0
votes
2answers
33 views

Integer input constraints

I want to make an input constraint on read: Terminal Shell; read x read y echo $(($x+$y)) I want to make a constraint of x, I want x to be -100 <= x <= 100. What's the command I insert ...
9
votes
4answers
479 views

Use #!/bin/sh or #!/bin/bash for Ubuntu-OSX compatibility and ease of use & POSIX

I know that I can use either as the first line of scripts to invoke the desired shell. Would #!/bin/sh be recommended if compatibility with all unix systems is an absolute requirement? In my case ...
2
votes
2answers
1k views

Changing user to root when connected to a linux server and copying files

My script is coded in a way that doesn't allow you to connect to a server directly by root. This code basically copies files a server to my computer and it works but I don't have access to many files ...
0
votes
2answers
66 views

Use .sh or .bash extension for bash scripts?

(See Use #!/bin/sh or #!/bin/bash for Ubuntu-OSX compatibility and ease of use & POSIX) If I want my scripts to use the bash shell, does using the .bash extension actually invoke bash or does it ...
1
vote
1answer
61 views

Running init script which starts a deamon in background for reducing boot time?

I'm looking for ways to speed up the boot time on a single core embedded Linux system. Significant lag happens during start up of some custom daemons. Once they are up, they do run in the background, ...
1
vote
3answers
66 views

Cronjob doesn't execute shell script, but when I am executing it standalone it works. Why?

Shell Type: >echo $SHELL /bin/ksh Cronjob : 15 * * * * /bin/ksh /wls_domains/resMGT/logs/bea/wlr3queuetransaction.sh > /wls_domains/resMGT/logs/bea/data/script.log The script is as below: ...
4
votes
3answers
1k views

recursive 'ls' giving absolute filenames

When I do 'ls -R' in a directory, I get something like ./dir1 dir2 file1.txt file2.txt ./dir1/dir2 file3.txt file4.txt but I would like a command that gives me ./dir1/file1.txt ./dir1/file2.txt ...
4
votes
3answers
6k views

Difference between ls -l and ll?

I'm relatively new to programming as a whole and some tutorials have been telling me to use ls -l to look at files in a directory and others have been saying ll. I know that ls is a short list, but ...
1
vote
4answers
51 views

Create copies of files in same directory

Lets say I have a directory with the following files: 1.txt 2.txt 3.txt I want to copy these and basically paste in the same directory making new files eg: 1.txt 1(1).txt 2.txt 2(1).txt 3.txt ...
4
votes
3answers
120 views

How to use GNU parallel effectively

Suppose I want to find all the matches in compressed text file: $ gzcat file.txt.gz | pv --rate -i 5 | grep some-pattern pv --rate used here for measuring pipe throughput. On my machine it's about ...
1
vote
2answers
60 views

How to extract a part of file name in unix/linux shell script

My file name is Oracle.2347263_testing_152607.csv I tried this : echo Oracle.2347263_testing_152607.csv | sed -e 's/.*G.//' \-e 's/.csv//' but I didn't get the result I expected. I want to ...
4
votes
2answers
891 views

Is there something like a lorem ipsum generator?

Is there something like a 'lorem ipsum generator'? I know it exists in Latex, and even in LibreOffice, but I'm looking for a terminal command. I would like to type something like loremipsum 10 ...
1
vote
2answers
211 views

How to find the cpu and memory usage of child processes

Supervisord is running on centos server. If I do ps -e -o %mem,%cpu,cmd | grep supervisord | awk '{memory+=$1;cpu+=$2} END {print memory,cpu}' I get 0 0 just because supervisord is just an ...
15
votes
5answers
2k views

Generating a random password; why isn't this portable?

I want to generate a random password, and am doing it like so: </dev/urandom tr -dc [:print:] | head -c 64 On my laptop, which runs Ubuntu, this produces only printable characters, as intended. ...
3
votes
3answers
3k views

Sending the output from 'dd' to awk/sed/grep

I'm trying to approximate the computer's write speed using dd: dd if=/dev/urandom of=/dev/null bs=1K count=10000 which gives the following output 10000+0 records in 10000+0 records out 10240000 ...
13
votes
4answers
1k views

Write Python stdout to file immediately

When trying to write the stdout from a Python script to a text file (python script.py > log), the text file is created when the command is started, but the actual content isn't written until the ...
3
votes
1answer
77 views

Triple dot wildcards

I have a very large directory structure of source code that is very difficult to work with. I would like to run a tool to transform it to a Maven like structure that works better for me. When I have ...
1
vote
0answers
34 views

Cannot change bash shell in Mac OS X

I'm trying to update bash shell on my Mac OS Mavericks. $ brew install bash $ which -a bash /bin/bash /usr/local/bin/bash $ which bash /bin/bash $ chsh -s /usr/local/bin/bash $ which bash /bin/bash ...
0
votes
1answer
79 views

“too many arguments in [ (test) statement”

this is my first "if-else" script on linux. It gives the error [: too many arguments Code: n=0 if [ $n % 2 -eq 0 ] then echo "even number" fi How to correct it.
2
votes
3answers
2k views

How to get previous year and previous month in solaris 8

How to get previous year and previous month in solaris 8? I have tried below command but none of them is correct: date +'%m' -d 'last month' date +'%Y' -d 'last year'
2
votes
1answer
46 views

Multi-month view in calendar (cal) in OS X

I am hoping to run some of the commands listed in this article, e.g.: cal -3 which is supposed to show me the last month, this month, and next month. This command does not work in OS X. $ cal -3 ...
8
votes
1answer
272 views

regarding portable sed -e… d b or ! b?

In this edit Stéphane Chazelas POSIXifies (again) my sed formatting by inserting an -expression break and another -expression statement. Now, I might just ask him why in the comments, I suppose, but ...
5
votes
4answers
266 views

How to move all files inside present subfolders up here

I have 50 folders with some subfolders too, with more than 1000 audio files total. I need to remove all subfolders and put all files in present level. Tried mv */* ./ but it complaints: argument list ...
19
votes
2answers
1k views

Pipes, how do data flow in a pipeline?

I don't understand how the data flows in the pipeline and hope someone could clarify what is going on there. I thought a pipeline of commands processes files (text, arrays of strings) in line by line ...
1
vote
1answer
33 views

Calling bash getopts from a function fails the 2nd time

I'm trying to parse arguments passed to a bash function using getopts inside that function. It works when the function is called for the first time but fails on all subsequent calls. Here is a simple ...
4
votes
1answer
69 views

Unix: Problem with cmp command

Let me give you an idea of what I am doing. I am running a script that is doing basic OS processes for two systems Linux and SunOS. Well the first directory it runs is called sol0. The script puts ...
2
votes
1answer
35 views

Intercept and modify commands in bash scripts

I have some scripts and some commands in the scripts are like this ./executable arg1 arg2 .. argn I want to change the above command to LD_PRELOAD=/some/lib ./executable my_arg1 my_argn arg1 arg2 ...
70
votes
6answers
41k views

Allow setuid on shell scripts

The setuid permission bit tells Linux to run a program with the effective user id of the owner instead of the executor: > cat setuid-test.c #include <stdio.h> #include <unistd.h> int ...