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)

4
votes
1answer
28 views

How to delete part of a binary file without copying

I need to delete the first 2 bytes of a 6MB file. However, this is an embedded Linux with only 32 Mbytes RAM and less than 1 MB free flash memory. I tried using dd, as: 1 - # dd bs=1 skip=2 ...
0
votes
0answers
14 views

Unrecoginzed option: using 'getopt' cmd in shell script

I'm new to shell and linux, it would be great if someone can help me find what is wrong in the command: command: if ! options=$(getopt -n myscript -l a:,b:,cc:,dd:,ee:,ff:,gg:,hh: -- "$@"); then ...
1
vote
1answer
17 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 ...
0
votes
2answers
23 views

What I am doing wrong with this bash variable? [on hold]

How can I insert a variable into a command? In the case below, I need to concatenate the command with the variable file name. #!/bin/bash # Define a timestamp function timestamp() { date +"%D-%T" ...
1
vote
1answer
22 views

How can I get $PATH to always include $(pwd)/sub_directory/.bin

If the path ~/dev/project1/node_modules/.bin/ionic exists, and my working directory is ~/dev/project1, I would like to be able to just type ionic and hit enter. I could include all those ...
3
votes
1answer
219 views

Chaining pipe | with &&

I have this command where I want to filter make output: cd /app && make && sudo nginx -g 'daemon off;' What is the correct way to insert make | pv -q -L 100 here?
-1
votes
2answers
21 views

if else statement

I have a case statement inside some of the if statement, but after doing the case statement inside the if statement, the loop ends. After the case statement, it is supposed to go to the next value on ...
0
votes
2answers
58 views

Using grep in shell script

I have a text file which looks like this(I am showing few lines of it) INDEX : 1 snRNA_seq:TTTTGGAGCAGGGAGATGGAAT miRNA_seq:CTCCTGACTCCAGGTCCTGTGT target: ...
1
vote
1answer
316 views

shell command to know computer manufacturing date [on hold]

as object, I would like to know when a computer was built and also last OS installation date
0
votes
1answer
28 views

How can I multiply a column by a variable and write out? [duplicate]

I would like to multiply a single column in a .txt file by a variable and then write to another .txt file. What am I missing from the awk line? Appreciate any help in advance. !/bin/bash ...
1
vote
0answers
56 views

What is the meaning of the string **/* when used with grep?

I came across this picture (below), obviously it is a pun or some kind of allusion incorporating command-line expressions. Frankly speaking I do not understand anything of it except for grep -n. ...
2
votes
1answer
35 views

Can we use two brace expansions together?

For example, I want to rename a file abc to bd. Why doesn't two brace expansions work? How shall I make brace expansion work in my example? Thanks. $ touch abc $ mv {a,}b{c,d} mv: target `bd' is not ...
1
vote
3answers
68 views

How do you parse through a subdirectory where the path contains spaces? [duplicate]

I'm trying to parse through a set of files in a directory on a mapped drive. However, I can't seem to resolve an issue that seems to be because of spaces in the path to the subdirectory. Would ...
0
votes
2answers
30 views

A batch that cout the number of occurrences

I've to extract the number of words using each letter of the alphabet from A to Z. The script that i've to create create take as parameter the name of the dictionary file to analyze and will be used ...
-3
votes
0answers
23 views

How to configure the Shell if no .bashrc exist ?

I have a problem with my Xfce Terminal, once I start it it does not respond for a minute. I was told here to change settings in the .bashrc configuration file. Unfortunately no such file exist. What ...
1
vote
1answer
23 views

How do I control output after executing a command?

.. Script Run Complete. You have new mail in /var/spool/mail/<user-name> -bash-3.2$ I have seen the above message most the times on my prompt, probably while it's idle or as soon as script ...
1
vote
2answers
69 views

Is there any way to make scripts dynamic? [on hold]

I need my script to show the time till next run, continuously like a timer, is this possible?
2
votes
1answer
37 views

Produce aligned columns in a shell script

In shell how do I have an even length of spaces by the length of words on my menu? I've tried to get the length of the longest character string and then create each column length by the longest ...
-2
votes
2answers
32 views

Not able to run shell script using cron [on hold]

I have a shell script test.sh in /home/username The test.sh file contains the following lines - #!/bin/sh cd /home/username/bin sh launch.sh ParameterName #launch.sh is in /home/username/bin ...
2
votes
2answers
25 views

How can I copy and move a sequential subset of files?

I have a directory containing 1772 files named PRC0001, PRC002,... up to PRC1772. How can I copy a subset, for example PRC0257 to PRC1516 to a different directory? I am trying to do this for several ...
1
vote
3answers
49 views

how to express line feed in shell?

Im my debian7.8 bash shell. str="deb http://ftp.cn.debian.org/debian/ wheezy main contrib non-free \n deb-src http://ftp.cn.debian.org/debian/ wheezy main contrib non-free " echo $str > ...
0
votes
1answer
40 views

Shell Concat string from config file

I have created config.cfg like this DB_USERNAME='abcdef' DB_PASSWORD='1234' Then my shell.sh have read config and try to concat string #! /bin/sh source config.cfg ...
0
votes
1answer
43 views

property file reading from unix shell [on hold]

Below is the sample code. products=$PRODUCTS arr=$(echo $products | tr "," "\n") for x in $arr do with="${x}SUBPRODUCTS" subproducts=$(echo "${x}SUBPRODUCTS") echo ...
3
votes
3answers
168 views

How to match * with hidden files inside a directory

How to match the hidden files inside the given directories for example If I give the below command it's not giving the result of the hidden files, du -b maybehere*/* how to achieve this ...
2
votes
1answer
32 views

What's the easiest way to detect what signals are being sent to a process?

I'm trying to debug an issue with my shell (specifically, fish) sending signals to my background processes. I'd like to be able to recognize what signals a process is receiving. Ideally, I'd like ...
2
votes
2answers
41 views

Why `until` block is designed as it is just a negative version of `while`?

To my understanding, until block is just the opposite version of while, like until "condition A is met" is equivalent to while "condition A is not met". In some modern languages such like python, ...
-1
votes
2answers
36 views

Just open the link [duplicate]

I just want to open a website link using the terminal in ubuntu. I am using the following code:- firefox https://anylink.com the problem is that once this command is executed, the terminal does not ...
5
votes
5answers
108 views

execute a command in $PATH matching a wildcard

I'd like to find and execute a command in the current $PATH matching this wildcard libreoffice?.? (eg. libreoffice4.0, libreoffice4.3, etc.) EDIT: if multiple matches are found, you can pick one ...
0
votes
2answers
40 views

Why can't I kill the shell using the PID obtained from the $$ special variable? [duplicate]

After I have learned that the $$ special variable holds the process number of the shell, I tried too kill the shell by simply: kill , however this did not work, I also tried some variations, but them ...
0
votes
2answers
37 views

What is the meaning of the number displayed by echo $$ ?

By accident I typed "echo $$" into the command line, but instead of an error message I got a 5 digit number. I repeated "echo $$" on different terminals and each time I got a 5 digit number. What is ...
0
votes
1answer
19 views

Historical bandwidth data in a console? (save/load statistics)

So, I found that nload and iftop displays the amount of data that passed and how fast. Now, is there anything like those that can save/load statistics? I want to measure the amount of data I download ...
0
votes
1answer
11 views

Calling of scripts between init.d and home directory of server

I have a script (server_up.sh)that automatically makes server up whenever server gets rebooted and is placed on linux server in home directory. I have made another script "up_server.sh" in init.d that ...
3
votes
1answer
134 views

eval limitation with piped commands

We have a shell script that builds a long piped command chain in a variable and executes it with eval (the following code is simplified to the essential): cmd="cat /some/files | grep -v \"this\" | ...
1
vote
2answers
56 views

linux/bash equivalent of mv -t

ls -al | grep -v '^d' | xargs mv -t mysubdir I use the above command extensively on Red Hat systems. It moves all files in the current directory to mysubdir $ mv --version Usage: mv [-f] [-i] [-e ...
0
votes
1answer
34 views

pass quoted string argument in sh script

I simply don't understand command-line (works): $ someprog -flag 'key1=val 1,key2=val 2,key3=val 3' sh direct (works): #!/bin/sh someprog -flag 'key1=val 1,key2=val 2,key3=val 3' sh variable ...
1
vote
1answer
42 views

Using the test command to create a directory if it doesn't exist

I was just wondering whether or not this script code would properly test for the existence of a dir2, and if it doesn't exist, then to create it. Dir1 already exists. [ ! -d /dir1/dir2 ] && ...
2
votes
3answers
81 views

What is a best practice to represent a boolean value in a shell script?

I know, that there are boolean values in bash, but I don't ever see them used anywhere. I want to write a wrapper for some often looked up information on my machine, for example, is this particular ...
14
votes
4answers
601 views

What is the difference between '$ . foo' and '$ ./foo'? [duplicate]

t is a simple script What is different between two case below : $ . t and $ ./t
1
vote
1answer
27 views

Redirection not overwriting file but just producing a blank one [duplicate]

I have a command that strives to just read a file and then comment out every single line in it indiscriminately, then overwrite the existing file. cat file | sed 's/^/#/g' > file But to my ...
0
votes
1answer
49 views

Run a Vim command from a bash script

This is related to a question I asked earlier but I would like to keep it separate in case anyone else can find use in it. I have a command that I am running on a file called dummy.out from the ...
2
votes
2answers
47 views

Bash command: is it possible to pass an argument before a custom command (function) or it must be only after:

I am wondering if it is possible to pass an argument to a custom command before the command? Let say I have custom command ping and I would like to pass the IP address before command: instead ping ...
-1
votes
0answers
22 views

Script to generate a report from a logfile [closed]

Need a BASH/perl script to generate a report from a logfile. Below is the log file example. TIME HOST SERVICE STATUS DESCRIPTION 1 A X CRITICAL DOWN 2 A ...
0
votes
1answer
37 views

Two errors when running ssh in a bash script [duplicate]

I try to run this script against a remote machine, to carry out login check, but have some problems executing it with no errors. I have the following error when I run the script: The Error: bash: -c: ...
3
votes
2answers
93 views

Select added lines from file

I have two versions of a file where the newer one has some lines added. The files are sorted (think of wordlists) and I want to print out the newly added lines (given file1 and file2). I know how to ...
-1
votes
1answer
33 views

Shell script to get all the directory starting with a certain letters

I need to write some shell script to get all the directory that start with certain letters and save the result list in a txt file eg. -all uppercase directory -all directory that starts with "Ab" ...
0
votes
0answers
23 views

printf>stdin unusable with read [duplicate]

With read, sending "a" to stdin is not equivalent to pressing "a" (or use your favorite letter/key). Tested this: ~$ read -n1 & fg [1] 11620 read Then "typed" "a" into the read process stdin ...
0
votes
1answer
40 views

unexpected end of file [closed]

Have written a small script for our Windows machine but getting the below mentioned error. syntax error: unexpected end of file.Can you please help me to resolve it. I have attached only part of my ...
0
votes
3answers
42 views

Running sh file only works if cd'd to scripts directory

I'm trying to run a .sh file, through the ./file.sh syntax. I, wrongly, thought it'd be possible to run: ./usr/bin/foo/bar.sh which just yields "No such file or directory". However, if I run: cd ...
2
votes
3answers
113 views

Processing input line by line (with empty lines) from shell

In a shell script, I need to parse the output of a command line-by-line. The output may include empty lines, and these are relevant. I am using ash, not bash, so cannot resort to process substitution. ...
-1
votes
1answer
36 views

killall fails some time

Hi below is the script which is intended to kill all instances of the process "processName" but sometimes it is not able to kill the process and we see double instance of the same process how can I ...