-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetalias.sh
More file actions
33 lines (27 loc) · 835 Bytes
/
Copy pathsetalias.sh
File metadata and controls
33 lines (27 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# Script to add alias ll='ls -alFh' to shell configuration
# Define the alias
ALIAS_LINE="alias ll='ls -alFh'"
# Check if ~/.bash_aliases exists, otherwise use ~/.bashrc
if [ -f "$HOME/.bash_aliases" ]; then
TARGET_FILE="$HOME/.bash_aliases"
else
TARGET_FILE="$HOME/.bashrc"
fi
# Check if the alias already exists in the target file
if grep -Fx "$ALIAS_LINE" "$TARGET_FILE" > /dev/null; then
echo "Alias 'll' already exists in $TARGET_FILE"
else
# Append the alias to the target file
echo "$ALIAS_LINE" >> "$TARGET_FILE"
echo "Added alias 'll' to $TARGET_FILE"
fi
# Source the target file to apply the alias in the current session
if [ -f "$TARGET_FILE" ]; then
source "$TARGET_FILE"
echo "Alias 'll' is now active in the current session"
else
echo "Error: $TARGET_FILE not found"
exit 1
fi
exit 0