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)

0
votes
0answers
23 views

Update process name in shell, is it possible?

In C/C++ it is in general possible to do strcpy(argv[0], "new process name"). It's a hack used in malicous software to hide real process name. Is such operation possible via shell? What I want to do ...
2
votes
2answers
29 views

find and sed (find and replace) causes illegal byte sequence on Mac OS X

I am attempting to perform a find and replace of underscores to dots in a directory for certain filetypes only (.mkv, .mp4, .avi). This is the code that I am using (I'm on Mac OS X 10.9): find . \( ...
3
votes
2answers
67 views

Using `case` to handle script arguments

Can I use the case statement to handle arguments? So, using -restart I'd like execute "-umount" and "-mount" #!/bin/bash case "$1" in -mount mount /ip/share1 /local/share1 ;; -umount umount ...
1
vote
1answer
19 views

How do I put a time stamp with: wget --output-file=[FILENAME] [URL]

So I've been trying to put a timestamp on some images I'm downloading from a webcam, but so far it's been saving the images with the names camera3_date' here's my line that I enter: wget ...
0
votes
1answer
15 views

check status process output

I wanted to understand how to create a script sh that allows me to see if an additional script functions correctly. For now this is the script that I created. if /run.sh status echo "$SERVICEXE ...
1
vote
2answers
48 views

Compare and print data from different text files to one in Shell

How can I compare and print data from different text files to one in Shell. I have captures NAS details of three different boxes using SSH, now I need to combine all the three text files to one file ...
0
votes
1answer
22 views

Trying to debug /etc/init.d/named, no output, replace > /dev/null with /var/log/named.log?

I'm trying to debug named, when I try: [root@test master]# service named start Starting named: [FAILED] it fails silently, so I tried: sed -i ...
23
votes
2answers
1k views

Why is using a shell loop to process text considered bad practice?

Is using a while loop to process text generally bad practice in POSIX shells? As Stéphane Chazelas pointed out, some of the reasons for not using shell loops are conceptual, reliability, legibility, ...
0
votes
1answer
36 views

How to keep running a process in Android when disconnecting adb terminal?

I'm trying to analyze the reason for random reboots of my phone (see here). Therefore I wanted to record the logcat and kernel messages till the restart to see the logs even after the usb disconnects, ...
4
votes
6answers
399 views

Command line tool to “cat” pairwise expansion of all rows in a file

Suppose I have a file (call it sample.txt) that looks like this: Row1,10 Row2,20 Row3,30 Row4,40 I want to be able to work on a stream from this file that is essentially the pairwise combination of ...
3
votes
4answers
280 views

How to use sed to selectively remove leading zeros

How can I substitute/remove 0's in this, using sed: 2001:0db8:03cd:0000:0000:ef45:0006:0123 to make it looks like this: 2001:db8:3cd:::ef45:6:123 There are 8 pieces of 4's divided by : in the ...
3
votes
2answers
105 views

single quote within double quotes and the bash reference manual

In section 3.1.2.3 titled Double Quotes, the bash manual says: Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception ...
12
votes
2answers
754 views

How can variables use “~” for cd'ing?

How can I use a variable - $BASE in my cd. I tried the following but I get an error $ cd ~/z/repo_1_ruby_193/ 23:23:57 durrantm Castle2012 /home/durrantm/z/repo_1_ruby_193 $ BASE="~/z" 23:24:03 ...
2
votes
2answers
110 views

How can I test for a file having a value?

I am using source ~/.rvm/scripts/rvm repos="repo_1_ruby_193 repo_2_ruby_211 repo_3_ruby_191" > rvm_check.txt for repo in $repos do cd ~/zipcar/$repo 2>rvm_check.txt cd .. echo $repo if ...
2
votes
3answers
63 views

Using a command's output to determine the name of the file to redirect output to

I want to run smartctl -a, and use the device serial number from that output as the name of the file to store the output in. I know this can be done by invoking smartctl twice, and slicing up the ...
-1
votes
0answers
36 views

Command line commands that every one needs to know! [on hold]

Well I'm new to Linux, and I have really never used a Command line before... So I have no idea of its potential. I know some of the basic commands like: apt-get xrandr aptitude clear startx ls cd ...
1
vote
2answers
178 views

how to shutdown another computers by using their IPs in shell script [on hold]

command to shutdown to collection of servers by IP in specific time by shell script "using ssh command"
1
vote
1answer
34 views

How do you make case statements with ranges

I'm supposed to: Make a case statement that will display the a grade after input. With no loop or conditional. A=90-100, B=80-89, C=70-79, D=60-69, F=0-59 This is what I have so far: ...
2
votes
3answers
145 views

How to create multiple files with different names and different extensions?

I'm trying to create some files that has different names and with different extensions. Let say I want to create for example 3 files with following name and extension: File001.000 File002.001 ...
1
vote
1answer
19 views

Root shell sees pip but sudo pip “command not found”

I have installed python 2.7.8 via make and make install and then pip via get-pip. I have to note that I work behind a proxy which I have set up via http_proxy ftp_proxy https_proxy in my user's ...
1
vote
3answers
64 views

0 byte file created in a simple script

I have a script as below: #!/bin/bash df -k | tr -s " " "," | awk 'BEGIN {FS=","} {print $1,$5}'|sed 1d > file1.txt while read partition percentUsed do if [ $percentUsed > 75 ] then echo ...
2
votes
2answers
84 views

How to read from a named pipe after the writer process exits?

I want to use named pipes as asynchrnonous task queues (JMS-like, perhaps). For example, suppose a client sends some data that I wish to insert into a database, but I want the client to disconnect ...
0
votes
0answers
10 views

od: Put offset n to n of a hexdump to a file in proper hexdump -C (hex+ASCII) format

I have a 155GB canonical hex+ASCII hexdump hexdump -C blah > dump.dp Then ran: strings dump.dp | grep -bo 'XXXX' > found.txt So now, that file contains the string's hex offset in the ...
2
votes
3answers
210 views

Bash File existence test is always true

I have the following lines of bash script to test whether a file exists: MYAPPPATH=$(find $APPDIR -iname myapp* -print) if [ -e $MYAPPPATH ] then echo "File exists" fi However when file ...
2
votes
2answers
47 views

Efficiently copy names in shell

I have noticed an efficient technique that some users use to quickly copy directory and file names in the terminal or shell. The behavior/usage is as follows: Issue ls Click on the desired entry, ...
22
votes
4answers
2k views

Is there a simple Bash tool which can quickly render basic HTML?

From time to time I need to do a simple task where I output basic HTML into the console. I'd like to have it minimally rendered, to make it easier to read at a glance. Is there a utility which can ...
1
vote
1answer
59 views

Sh Script using ftp to put a list of files

So my Script looks something like this: #... files="$(find $line/processed/* 2>/dev/null)" #2>/dev/null used for error output suppression if [[ ! -z "$files" ]] then ...
1
vote
1answer
178 views

How to get owner and full path of 50 large size file across all users?

Below command list top 50 files regardless of subfolders. $ls -lR /root/home | sort +4 -5nr | head -50 Current Result: -rw-r--r-- 1 john dpst 192954384 Nov 7 07:36 filenxx1.gz ...
1
vote
2answers
32 views

Store stdout in variable and send command to background

I have a command in a bash script which I want to capture the output of and then send it to the background. How do I get this done? The following doesn't seem to work (it keeps blocking and outputs ...
3
votes
1answer
54 views

how to run multiple versions of one shell on a single machine

In order to test some scripts1 in as many environments as possible, I've set up several VMs with UNIX (or Unix-like operating systems): Linux Solaris OS X2 FreeBSD I assume, though, that in many ...
0
votes
1answer
24 views

How do I add text to an output file?

I have a script for doing whois lookups: #!/bin/bash for domain in `cat /Users/jason/Desktop/letters.txt `; do echo $domain >> /Users/jason/Desktop/whois-results.txt whois $domain | grep ...
5
votes
3answers
271 views

How to iterate a zero padded integer in bash?

How does one iterate a string with the form "[A-Z][0-9]*" Or for example: "A000001"? After receiving the variable I split: current_=$(mysql -h"$mysqlhost" -u"$mysqluser" -p"$PASS" "$DBNAME" -se ...
3
votes
1answer
42 views

Run vsim from dmenu — it only works when directly invoked in the terminal

Works: vsim, sh -c vsim Doesn't work: echo "vsim" | sh, echo "vsim" | xargs -I {} sh -c "{}" I want to run ModelSim (vsim) with dmenu, which is triggered using xbindkeys. Details vsim is a ...
1
vote
2answers
38 views

How to find number of Subdirectories under a given directory

In windows you get a count of the number of subdirectories within a directory.Is there any equivalent on Linux ? I'd like it to count recursively & Not stop at a single level.
1
vote
1answer
32 views

Make parent directories while creating a new file

I am aware of the fact that mkdir -p /path/to/new/directory will create a new directory, along with parent directory (if needed ). If I have to create a new file, along with it's parent directories ...
0
votes
1answer
37 views

How to ssh and execute a remote script within a local shell script?

I have a shell script which will kick off a series of jobs on a remote server. I can ssh into this server (but it does require a password!) and run the scripts manually, but there are certain steps ...
0
votes
2answers
41 views

Convert a float to the next integer up as opposed to the nearest?

The context is there are 2 variables that get divided to a floating point result like so: printf "%0.5f\n" $(echo 305/15 | bc -l) 20.33333 How can I always round up to the next integer i.e. 21? ...
2
votes
3answers
50 views

Remove files from listing that are created/modified on Saturday

I am not sure if it is possible. I do ls -l, it gives all the files in the current directory. Is there a way to say list only files that weren't created/modified on Saturday's with shell command?
2
votes
1answer
26 views

Problems with find, xargs and egrep

I this is what I what I'm trying to end up with (except working) find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 egrep -vZ 'vvv|iii' What am I doing wrong? $ ll total 0 -rw-rw-r-- 1 ...
0
votes
1answer
39 views

Command not found when run with sudo bash

I ssh into my machine and then, in order to run some commands, I need to sudo bash first. In an interactive terminal session, if I do this: [vagrant@33 ~]$ sudo bash [root@33 vagrant]# which bundle ...
0
votes
2answers
43 views

How to list files and directories of a mount point

Given a mountpoint such as /dev/sda1 how can I list the contents of this file system using shell script. My objective is to delete the oldest file in this drive.
0
votes
2answers
23 views

Number of occurences of letters in a word?

I would like to find out the number of occurrences of each of the alphabets in a word. Eg input aabbbddd output a@2 b@3 c@0 d@3 How can I perform this using shell script?
1
vote
1answer
30 views

Using double or no quotes with wildcards

I came across this article which attempts to explain the find command.It gives an example of find /tmp -iname "data*.txt" now this article here states that Double quotes do not suppress the ...
2
votes
4answers
68 views

unix test when to use eq vs = vs == in test commands?

When should I use -eq vs = vs == e.g. [[ $num -eq 0 ]] [[ $num = 'zzz' ]] I've observed a pattern of using -eq (and -ne, etc.) for numbers and = for strings. Is there a reason for this and ...
3
votes
2answers
69 views

Execute code on remote machine and copy the results back

I'm using some old Fortran code that uses some peculiar memory handling. To make the long story short, it runs on my local machine but fails on the remote one. This is why I would like to ssh to my ...
28
votes
7answers
2k views

Is test or [ or [[ more portable both between bash shells and between other shells?

I see I can do $ [ -w /home/durrantm ] && echo "writable" writable or $ test -w /home/durrantm && echo "writable" writable or $ [[ -w /home/durrantm ]] && echo ...
2
votes
2answers
112 views

Left and right square brackets treated differently by sed/bash

I have a file with the following contents: [root@server list]# cat filenames.txt [AAA','ACMEDEMO2','ACMEDEMO3','ACMEDEMO4','RENTCOGH','TESTENT','DORASINE','LOKAWINK','BBB] [root@qa4app01 list]# I ...
3
votes
2answers
72 views

What is the format for piping a message into sendmail?

I am using the following command to create messages on the fly, and send them: echo "Subject:Hello \n\n I would like to buy a hamburger\n" | sendmail email@example.com It seems that when you send ...
4
votes
1answer
39 views

Are there problems with hyphens in functions, aliases, and executables?

In my testing (in Bash and Z Shell), I saw no problems with defining functions or aliases or executable shell scripts which have hyphens in the name, but I'm not confident that this will be okay in ...
4
votes
3answers
147 views

Change case of n-th letter in a string

I want to change the case of the n-th letter of a string in BASH (or any other *nix tools, e.g. sed, awk, tr, etc). I know that you can change the case a whole string using: ${str,,} # to lowercase ...