Questions tagged [bash-script]

Scripts written in the bash shell language. Most questions should use the tags /bash and /shell-script instead.

A for the shell. Use the tags and instead.

90 questions
72
votes
9 answers

Bash script to get ASCII values for alphabet

How do I get the ASCII value of the alphabet? For example, 97 for a?
xmpirate
  • 913
  • 2
  • 7
  • 6
47
votes
3 answers

Variable as command; eval vs bash -c

I was reading a bash script someone made and I noticed that the author doesn't use eval to evaluate a variable as a command The author used bash -c "$1" instead of eval "$1" I assume using eval is the preferred method and it's probably faster…
biepbiep
  • 571
  • 1
  • 4
  • 4
47
votes
3 answers

How to get IP Address using shell script?

Want to get the IP address using Shell script. Without knowing the eth0 or eth1 or eth2 How to get the particular IP address. I am not interest to get localhost address, want to get private IP address.
Beginner
  • 1,920
  • 5
  • 21
  • 34
36
votes
5 answers

Bash in Linux v.s Mac OS

I am buying an iMac. I've been working on Linux for a long time and I do a bunch of bash scripting. I was wondering if all the bash commands and features are available on Mac OS ? Anyone has any experience with Mac bash scripting ? I appreciate your…
alex
  • 361
  • 1
  • 3
  • 3
36
votes
8 answers

Are there any well known and well used shell scripting IDEs for Un*x?

Are there any IDEs targeted at shell scripting, specifically bash and zsh scripts? This means having syntax-highlighting for shell scripts and more importantly debugging environments with features like breakpoints, variable inspection and…
vfclists
  • 7,215
  • 14
  • 51
  • 79
26
votes
9 answers

How to detect the desktop environment in a bash script?

I am writing a bash script that needs to know which desktop environment (XFCE, Unity, KDE, LXDE, Mate, Cinnamon, GNOME2, GNOME3,... ) is running. How can I obtain that information?
Serge Stroobandt
  • 2,314
  • 3
  • 32
  • 36
23
votes
1 answer

Execute command supplied by function parameters

I'm trying to create a function method in a bash script that executes a command which is supplied to the method by the paramters. Meaning somethings like this: special_execute() { # Some code # Here's the point where the command gets…
BrainStone
  • 3,534
  • 12
  • 32
  • 53
23
votes
4 answers

How to delete files only, but keep the directory structure?

I would like to delete every file, but keep the folder structure. Is there a way? NOTE: (I'm using GNU bash 4.1.5).
The Student
  • 3,439
  • 9
  • 30
  • 34
18
votes
9 answers

A bash function that takes argument like other languages?

I have a bash function to set the $PATH like this -- assign-path() { str=$1 # if the $PATH is empty, assign it directly. if [ -z $PATH ]; then PATH=$str; # if the $PATH does not contain the substring, append it with ':'. …
ramgorur
  • 431
  • 2
  • 4
  • 13
17
votes
2 answers

How to strip color codes out of stdout and pipe to file and stdout

I have a program that uses printf with some tput mixed in it and I'd like to pipe the output to stdout as well as a file. I'd prefer to use sed since I don't want any unnecessary dependencies on my script. Here's what I've got so far. printf…
iamnewton
  • 281
  • 1
  • 2
  • 7
15
votes
1 answer

How to assign result of sed to variable

Below is a complete copy of a demo I'm using to to figure out to get the sed command to get rid of the spaces in a persons name, and compress it down to not have spaces. Once this is done, I want to assign it to the variable comp then I can re-use…
Danijel-James W
  • 1,735
  • 4
  • 16
  • 19
12
votes
2 answers

Regular expression in bash script

This is my first time bash scripting so I'm probably making an easy mistake. Basically, I'm trying to write a script that gets the groups of a user, and if they are in a certain group, it will log that accordingly. Evidently there will be more…
jrdn
  • 223
  • 1
  • 2
  • 8
12
votes
2 answers

Writing starting from a certain line number in a text file

In a bash script I want to write some lines to a text file, but this file has already been used before and there are texts in it. So I want to echo some additional text in it, starting from a certain line number in the file. I want something like…
Ahmed Zain El Dein
  • 643
  • 2
  • 7
  • 8
11
votes
4 answers

How to remove any string from a file via shell scripts?

I try to remove string from .bash_profile. String is added when my shell script run: My string at bash_profile as follows: # for Myapllication export MYAPP_HOME=/opt/myapp I want to remove the strings from .bash_profile when myapp is removed via…
Gyhot
  • 267
  • 2
  • 4
  • 9
10
votes
3 answers

Script to prevent screen blanking using "mouse move" doesn't work

This is my attempt to make a script that will use a "mouse move" to prevent screen blanking while watching videos. I'm hoping to use the value for highest CPU% process in top and if CPU usage exceeds 5%, a mouse move should occur. #!/usr/bin/env…
user15760
1
2 3 4 5 6