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)

10
votes
2answers
10k views

How to reset a shell environment?

This issue has been bugging me for a while, and although I've thought I've found my answer through EnvWatcher, unfortunately it only works on Bash. And I use zsh. I would like to replicate the things ...
0
votes
1answer
30 views

Run shell scripts with -x for debugging system v boot

I need to debug the userspace part of the boot process and would like to run all the scripts with sh -x by default so I can observe what’s happening during boot. It's an embedded system that's using ...
8
votes
6answers
32k views

How to search for a word in entire content of a directory in linux

need to search for something in entire content I am trying: find . | xargs grep word I get error: xargs: unterminated quote How to achieve this?
19
votes
3answers
7k views

Are there naming conventions for variables in shell scripts?

Most languages have naming conventions for variables, the most common style I see in shell scripts is MY_VARIABLE=foo. Is this the convention or is it only for global variables? What about variables ...
1
vote
4answers
94 views

Set, backup and restore colors in the terminal

I use this program to display all color available in the terminal. That waht I get: This program doesn't show me colors below 100. Why? Is there a way to display them. Is the are way to change ...
0
votes
1answer
35 views

tail file from remote server and nslookup on local

I need a script for resolve hosts. For now I run this script on local machine for i in `tail -F access.log | awk '{print $8}' | awk '{gsub("http://|/.*","")}2' | awk '{gsub("http://|:.*","")}1' | ...
2
votes
2answers
98 views

Find differences in file and sorting file by key

So I have two language files, english and french. They are in this format: key=translation An example in English would be: ui.title=My Title And in French: ui.title=Mon Titre So I need a ...
0
votes
0answers
23 views

Create and Write .properties file

I need to write a shell script to create and write a file with .properties extension, that contains 3 values, where the first 2 values are user-defined and constant, the 3rd value will be the filename ...
3
votes
2answers
57 views

Convert a value into a “Binary Number” in a shell script

I know of bc: $> var="304" $> echo "obase=2; $var" | bc 100110000 Could it be done in shell (no external call)? This question: Binary to hexadecimal and decimal in a shell script Asks how to ...
-1
votes
1answer
29 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 ...
6
votes
3answers
284 views

Print random lines respecting the order of the source file

I have a large text file (~500K lines) with short sentences (couple of words long). Additionally, there is some XML markup in most of the lines. Finally, the text file has been sorted before the ...
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 ...
0
votes
2answers
2k views

Why doesn't alias work in AIX (Korn shell, .profile)?

I have these files in my home directory: drwxr-xr-x 3 meuser staff 256 Oct 12 13:11 . drwxr-xr-x 102 bin bin 4096 Sep 30 12:28 .. -rw------- 1 meuser staff ...
0
votes
1answer
2k views

How to execute Netscaler commands through a remote machine via SSH connection

I have been trying to execute some NetScaler commands like "bind" & "unbind" through a Linux Box via an SSH Connection. Now the Problem is, Manually we are able to enter & execute commands on ...
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 ...
0
votes
1answer
23 views

How shell get control of the terminal after wait()?

We know shell forks(),assigns it to a different process group and make it the foreground process group such that cntrl-c and cntrl-z will go to the child process group and the parent waits on it. ...
1
vote
1answer
42 views

Why are arguments of a command altered when viewed by ps?

When I run my favorite app, why the arguments look different when viewed by ps? $ redshift -l 12.94:43.75 2>/dev/null 1>&2 & [1] 8637 $ ps -o cmd= -C redshift redshift -l 12.94 43.75 ...
0
votes
2answers
48 views

Must I add “>&2” in the end of echo command?

For example #!/bin/bash INT=-5 if [[ "$INT" =~ ^-?[0-9]+$ ]]; then echo "INT is an integer." else echo "INT is not an integer." >&2 exit 1 fi When I delete ">&2". There is ...
2
votes
3answers
48 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 ...
2
votes
3answers
56 views

How to make an alias permanent?

I have created an alias: alias shh='sqlplus hfdora/hfdora@hfd1" After creating this alias I was able to enter my database only by typing shh. But after closing my shell, I wasn't able to find ...
0
votes
1answer
30 views

How to list only the file names of the same type in the directory?

I got a two group of files in the same directory *fmb and *fmx. I'm a rookie using Linux Terminal, and I want to learn how to print only the file name of fmb files, file1.fmb, file2.fmb, file3.fmb ...
2
votes
2answers
53 views

What other special characters are there?

For filenames, I know that you have to use either a double quotes or a backslash to include a space in your file name. Like mkdir "I like coffee" is the same as mkdir I\ like\ coffee Now when you ...
2
votes
4answers
167 views

How do I *reliably* and *simply* get the current shell interpreter name?

I'm looking for a simple and reliable way to get the name of the current shell from inside a script or a sourced file (not from the command line). I would have expected to just do $(basename ...
2
votes
1answer
43 views

Do not wait until the return for Shell redirection

I would like to redirect the output of a script (Python or any other kind) to a file. Easy to do with > or >>. But with these two the output seems to be written in the file only once the script ...
0
votes
0answers
24 views

Unable to specify a paper tray with bash script

So we use a bash script that sends control codes before printing to set some things on the printer. At the end of the script it calls a standard lp command. I add the option to print to a specific ...
2
votes
1answer
62 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 ...
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 а́ ...
28
votes
6answers
10k views

How to make bidirectional pipe between two programs?

Everyone knows how to make unidirectional pipe between two programs (bind stdout of first one and stdin of second one): first | second. But how to make bidirectional pipe, i.e. cross-bind stdin and ...
5
votes
1answer
33k views

Syntax error near unexpected token `('

When I use below code in SSH terminal for CentOS it works fine: paste <(printf "%s\n" "TOP") But if I place the same line code in a shell script (test.sh) and run shell script from terminal, it ...
6
votes
4answers
6k views

What's the meaning of a dot before a command in shell?

While following android eclipse debug tutorial, I encounter following commands. cd /path/to/android/root . build/envsetup.sh lunch 1 make emulator My problem is what the dot before ...
2
votes
1answer
65 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
33 views

How do you sudo with xonsh?

I get the error xonsh: subprocess mode: permission denied: sudo.
1
vote
2answers
1k views

Running system bash command in PHP script - syntax error: unexpected T_LNUMBER

If anyone can shed some light on my issue that'd be great. Please don't down-vote me; I'm new to the language and the OS itself and I'm trying my best to research before asking questions, so any ...
0
votes
2answers
58 views

File exists but mv errors out with: “mv: cannot stat ‘file.tar.gz’: No such file or directory”

I am creating a script in Centos 7 to move the latest file within a directory to another directory. The original directory that I'm copying from contains a valid file, however when I try to move or ...
11
votes
4answers
19k 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 ...
35
votes
7answers
3k views

Is `~/Documents` a relative or an absolute path?

This is merely just a vocabulary question, but which keeps turning around in my head. It comes from a practice exam from a LPIC preparation book. The correct answer according to the book is that ...
-1
votes
2answers
66 views

How do I take a prompt response and send it to a text file?

I'm new to shell scripting and I need help I want to ask the user what is their ORACLE_SID, ORACLE_HOME, and then send the output in a file. I want to create a param file that has ORACLE_HOME= ...
0
votes
0answers
36 views

Concatenating two strings cuts string

I extract two numerical strings from a textfile and and want to combine them to create a new string. The new string will be a filename. This is the textfile dates.dat: 378464,2015-01-31 ...
0
votes
1answer
37 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 ...
3
votes
3answers
116 views

Print man pages with fixed width

With the example command man apropos > outputfile a text file is generated which contains the formatted man page of apropos (with some little differences with respect to man apropos directly ...
3
votes
5answers
1k views

How to read certain lines after a find some text?

How i can read a certain number of lines after find some text? Eg.: Read next 2 lines after find "Unix" on: Test 1 Test 2 Test 3 Test 4 UNIX Test 5 Test 6 Test 7 Test 8 Test 9 Result can be: ...
1
vote
2answers
56 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 ...
1
vote
1answer
57 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' ...
5
votes
4answers
2k views

How can I search for a file with fixed name length using ls?

In a directory, I have files like lazer_100506 lazer_100707 lazer_091211 lazer_110103 lazer_100406_temp lazer_100622#delete etc How can I get a listing of only the first four files? $ ls ...
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 ...
0
votes
2answers
16 views

Assigning output of a Dynamic Performance View (v$asm_diskgroup) to a variable in Shell Script

I am trying to assign the output of select name from v$asm_diskgroup; to a variable in Shell . The script is failing because of special character '$' in the table name . Note : While i ...
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 ...
0
votes
2answers
62 views

Display CPU cores usage in percentage without using top

I am using java to run a command on linux. Since top is an interactive command and need to press 1 to get the info of all the cpu(s) so I cannot use that. So I am using the following command to get ...
18
votes
4answers
16k views

Solving “mv: Argument list too long”?

I have a folder with more than a million files that needs sorting, but I cant really do anything because mv outputs this message all the time -bash: /bin/mv: Argument list too long I'm using this ...